Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tdr/add namespace #4

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add new helper functions 'dilaz_metabox_get_use_type', 'dilaz_metabox…
…_theme_params', 'dilaz_metabox_plugin_params' from Dilaz-Metabox-Options/load.php
  • Loading branch information
Rodgath committed Feb 3, 2025
commit 9feea1812186dbf34bbe23d6e2873235f0de3c5b
84 changes: 84 additions & 0 deletions dilaz-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,90 @@ public function loadGoogleFonts() {
}
}

# Dilaz metabox get use type based on current metabox usage
function dilaz_metabox_get_use_type($filename) {
if (false !== strpos(dirname($filename), '\plugins\\') || false !== strpos(dirname($filename), '/plugins/')) {
return 'plugin';
} else if (false !== strpos(dirname($filename), '\themes\\') || false !== strpos(dirname($filename), '/themes/')) {
return 'theme';
} else {
return false;
}
}

# Dilaz metabox theme object
function dilaz_metabox_theme_params($theme_object, $filename) {

$theme_name = is_child_theme() ? $theme_object['Template'] : $theme_object['Name'];
$theme_name_lc = strtolower($theme_name);
$theme_version = $theme_object['Version'];
$theme_uri = is_child_theme() ? get_stylesheet_directory_uri() : get_template_directory_uri();
$theme_folder = basename($theme_uri);

/*
* If the theme folder name string appears multiple times,
* lets split the string as shown below and focus only
* on the last theme folder name string
*/
$split_1 = explode('includes', dirname($filename));
$split_2 = explode($theme_folder, $split_1[0]);
$split_2_last = array_pop($split_2);

$use_type_parameters = array(
'item_name' => $theme_name,
'item_version' => $theme_version,
'item_url' => trailingslashit($theme_uri),
'dir_url' => trailingslashit($theme_uri . wp_normalize_path($split_2_last)),
);

return $use_type_parameters;
}

# Dilaz metabox plugin object
function dilaz_metabox_plugin_params($filename) {

if (!function_exists('get_plugin_data')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

$plugin_data = [];

$plugins_dir = trailingslashit(WP_PLUGIN_DIR);
$plugin_basename = plugin_basename($filename);
$plugin_folder = strtok($plugin_basename, '/');

# use global to check plugin data from all PHP files within plugin main folder
foreach (glob(trailingslashit($plugins_dir . $plugin_folder) . '*.php') as $file) {
$plugin_data = get_plugin_data($file);

# lets ensure we don't return empty plugin data
if (empty($plugin_data['Name'])) continue; else break;
}

$plugin_name = $plugin_data['Name'];
$plugin_name_lc = strtolower($plugin_name);
$plugin_version = $plugin_data['Version'];

/*
* If the theme name string multiple times, lets
* split the string as show below and focus only
* on the last theme name string
*/
$split_1 = explode('includes', plugin_dir_url($filename));
$split_2 = explode($plugin_folder, $split_1[0]);
$split_2_last = array_pop($split_2);
$split_3 = array($split_2_last, implode($plugin_folder, $split_2));

$use_type_parameters = array(
'item_name' => $plugin_name,
'item_version' => $plugin_version,
'item_url' => trailingslashit($split_3[1].$plugin_folder),
'dir_url' => trailingslashit($split_3[1].$plugin_folder.wp_normalize_path($split_3[0])),
);

return $use_type_parameters;
}

/* Add update checker */
require_once plugin_dir_path(__FILE__) . 'inc/update-checker/plugin-update-checker.php';

Expand Down