2015-05-26 46 views
1

这是一个函数,它在我正在使用的插件内的函数文件中。如何使用函数更改此插件数组中的值?

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&hellip;', 'wp-job-manager')

难道我能不编辑插件功能来改变这个值,也许是我自己加的功能函数.php来覆盖它?

+0

该部分来自翻译。如果您想更改翻译结果,请在WP后端上执行。 – harrrrrrry

+0

看起来你可以传入一个数组,它拥有''placeholder''键中指定的内容,'wp_parse_args'应该将默认值和参数合并在一起。见[这里](https://codex.wordpress.org/Function_Reference/wp_parse_args) –

回答

0

您应该将自己的参数传递给此函数。有$ defaults数组包含默认值。

尝试这样的事情。

$myArgs = array('placeholder' => 'My sample text'); 
job_manager_dropdown_categories($myArgs); 

编辑:

尝试使用这些过滤器。

add_filter('gettext', 'translate_text'); 
add_filter('ngettext', 'translate_text'); 

function translate_text($translated) { 
    $translated = str_replace('Choose a category&hellip;', 'YOUR TEXT', $translated); 
    return $translated; 
} 
+0

嗨,谢谢我认为这肯定会奏效。但是,当我添加到我的主题functions.php我得到这个错误: 致命错误:调用未定义的函数job_manager_dropdown_categories()在/data01/marketin/public_html/f1rstcommercial/wp-content/themes/f1rstcomm/functions.php在线81 – Nervewax

+0

我认为这是因为functions.php没有看到这个函数。你想永久改变你的占位符吗? – czeski

+0

我正在寻找一种方法来避免直接更改插件功能,因为如果更新插件它们将被覆盖。如果有办法我可以永久改变价值,那也可以。 – Nervewax