这是一个函数,它在我正在使用的插件内的函数文件中。如何使用函数更改此插件数组中的值?
function job_manager_dropdown_categories($args = '') {
$defaults = array(
'orderby' => 'id',
'order' => 'ASC',
'show_count' => 0,
'hide_empty' => 1,
'child_of' => 0,
'exclude' => '',
'echo' => 1,
'selected' => 0,
'hierarchical' => 0,
'name' => 'cat',
'id' => '',
'class' => 'job-manager-category-dropdown ' . (is_rtl() ? 'chosen-rtl' : ''),
'depth' => 0,
'taxonomy' => 'job_listing_category',
'value' => 'id',
'multiple' => true,
'show_option_all' => false,
'placeholder' => __('Choose a category…', 'wp-job-manager')
);
$r = wp_parse_args($args, $defaults);
if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
$r['pad_counts'] = true;
}
extract($r);
// Store in a transient to help sites with many cats
$categories_hash = 'jm_cats_' . md5(json_encode($r) . WP_Job_Manager_Cache_Helper::get_transient_version('jm_get_' . $r['taxonomy']));
$categories = get_transient($categories_hash);
if (empty($categories)) {
$categories = get_terms($taxonomy, array(
'orderby' => $r['orderby'],
'order' => $r['order'],
'hide_empty' => $r['hide_empty'],
'child_of' => $r['child_of'],
'exclude' => $r['exclude'],
'hierarchical' => $r['hierarchical']
));
set_transient($categories_hash, $categories, DAY_IN_SECONDS * 30);
}
$name = esc_attr($name);
$class = esc_attr($class);
$id = $id ? esc_attr($id) : $name;
$output = "<select name='{$name}[]' id='$id' class='$class' " . ($multiple ? "multiple='multiple'" : '') . " data-placeholder='{$placeholder}'>\n";
if ($show_option_all) {
$output .= '<option value="">' . $show_option_all . '</option>';
}
if (! empty($categories)) {
include_once(JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-category-walker.php');
$walker = new WP_Job_Manager_Category_Walker;
if ($hierarchical) {
$depth = $r['depth']; // Walk the full depth.
} else {
$depth = -1; // Flat.
}
$output .= $walker->walk($categories, $depth, $r);
}
$output .= "</select>\n";
if ($echo) {
echo $output;
}
return $output;
}
我怎么会更改以下值不直接编辑此功能:
'placeholder' => __('Choose a category…', 'wp-job-manager')
难道我能不编辑插件功能来改变这个值,也许是我自己加的功能函数.php来覆盖它?
该部分来自翻译。如果您想更改翻译结果,请在WP后端上执行。 – harrrrrrry
看起来你可以传入一个数组,它拥有''placeholder''键中指定的内容,'wp_parse_args'应该将默认值和参数合并在一起。见[这里](https://codex.wordpress.org/Function_Reference/wp_parse_args) –