我正在尝试替换WordPress插件(简单属性列表)中的函数,但目前没有成功。
在类中这样添加操作:
<?php
/**
* Search Object
*
* @package EPL
* @subpackage Classes/Search
* @copyright Copyright (c) 2016, Merv Barrett
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
// Exit if accessed directly
if ( ! defined( \'ABSPATH\' ) ) {
exit;
}
/**
* EPL_Search_Fields Class
*
* @since 3.0
* @author Taher Atashbar <[email protected]>
*/
class EPL_Search_Fields {
/**
* Initialize hooks.
*
* @since 3.0
* @return void
*/
public function init() {
// Initialize hooks for displaying search frontend fields.
add_action( \'epl_frontend_search_field_text\', array( $this, \'render_text\' ), 10, 5 );
add_action( \'epl_frontend_search_field_checkbox\', array( $this, \'render_checkbox\' ), 10, 5 );
add_action( \'epl_frontend_search_field_select\', array( $this, \'render_select\' ), 10, 5 );
add_action( \'epl_frontend_search_field_multiple_select\', array( $this, \'render_multiple_select\' ), 10, 5 );
add_action( \'epl_frontend_search_field_number\', array( $this, \'render_number\' ), 10, 5 );
add_action( \'epl_frontend_search_field_hidden\', array( $this, \'render_hidden\' ), 10, 5 );
add_action( \'epl_frontend_search_field_radio\', array( $this, \'render_radio\' ), 10, 5 );
add_action( \'epl_frontend_search_field_checkbox_multiple\', array( $this, \'render_checkbox_multiple\' ), 10, 5 );
}
View the file on Github
我尝试替换的函数是render\\u select。在文件的下面:
/**
* Renders search frontend Select field.
*
* @since 3.0
* @param array $field
* @param string $config
* @param string $value
* @param string $post_type
* @param string $property_status
* @return void
*/
public function render_select( array $field, $config = \'\', $value = \'\', $post_type = \'\', $property_status = \'\' ) {
if ( isset( $field[\'wrap_start\'] ) ) {
echo \'<div class="\' . $field[\'wrap_start\'] . \'">\';
}
?>
<div class="epl-search-row epl-search-row-select epl-<?php echo $field[\'meta_key\']; ?> fm-block <?php echo isset( $field[\'class\'] ) ? $field[\'class\'] : \'\'; ?>">
<label for="<?php echo $field[\'meta_key\']; ?>" class="epl-search-label fm-label">
<?php echo apply_filters( \'epl_search_widget_label_\' . $field[\'meta_key\'], $field[\'label\'] ); ?>
</label>
<div class="field">
<select
name="<?php echo $field[\'meta_key\']; ?>"
id="<?php echo $field[\'meta_key\']; ?>"
class="in-field field-width">
<option value="">
<?php echo apply_filters( \'epl_search_widget_option_label_\' . $field[\'option_filter\'], __( \'Any\', \'easy-property-listings\' ) ); ?>
</option>
<?php
if ( isset( $field[\'options\'] ) && ! empty( $field[\'options\'] ) ) {
foreach ( $field[\'options\'] as $k => $v ) {
echo \'<option value="\' . esc_attr( $k ) . \'"\' . selected( $k, $value, false ) . \'>\' . $v . \'</option>\';
}
}
?>
</select>
</div>
</div>
<?php
if ( isset( $field[\'wrap_end\'] ) ) {
echo \'</div>\';
}
}
我正在尝试删除搜索栏中选择输入中的第一个选项值:
<option value="">
<?php echo apply_filters( \'epl_search_widget_option_label_\' . $field[\'option_filter\'], __( \'Any\', \'easy-property-listings\' ) ); ?>
</option>
因此,我只是复制了这个render\\u select函数,但插件中没有“option”,我将其命名为“render\\u select2”,它可以正常工作。在没有第一个选项值的情况下,我将选择输入加倍。
现在,我尝试删除初始操作。我尝试了很多代码(在这个论坛和谷歌的一些帖子上),但都没有成功。
在我的功能中。php:
function remove_searchfield() {
$class = \'EPL_Search_Fields\'; // Name of class the method was built in.
$tag = \'epl_frontend_search_field_select\'; // the name of the hook
$function = \'render_select\'; // the function you wish to remove
$priority = 10; // must be an integer
global $class;
remove_action ( $tag, array( $class, $function ), $priority);
}
add_action( \'init\', \'remove_searchfield\');
你们知道怎么做吗?我的PhP知识有限,我快疯了;)。
欢迎提供任何建议。
非常感谢。