Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Wordpress中正确重写类方法?_Php_Wordpress - Fatal编程技术网

Php 如何在Wordpress中正确重写类方法?

Php 如何在Wordpress中正确重写类方法?,php,wordpress,Php,Wordpress,如何正确重写该类预览\u处理程序的类方法,是否可以在子类中进行重写 class WP_some_class { public function __construct() { add_action( 'wp', array( $this, 'process' ) ); $this->steps = (array) apply_filters( 'submit_job_steps', array( 'submit' => array( 'name'

如何正确重写该类预览\u处理程序的类方法,是否可以在子类中进行重写

class WP_some_class {

public function __construct() {
add_action( 'wp', array( $this, 'process' ) );

$this->steps  = (array) apply_filters( 'submit_job_steps', array(
    'submit' => array(
        'name'     => __( 'Submit Details', 'wp-job-manager' ),
        'view'     => array( $this, 'submit' ),
        'handler'  => array( $this, 'submit_handler' ),
        'priority' => 10
        ),
    'preview' => array(
        'name'     => __( 'Preview', 'wp-job-manager' ),
        'view'     => array( $this, 'preview' ),
        'handler'  => array( $this, 'preview_handler' ),
        'priority' => 20
    ),
    'done' => array(
        'name'     => __( 'Done', 'wp-job-manager' ),
        'view'     => array( $this, 'done' ),
        'priority' => 30
    )
) );

public function preview_handler() {
    // .. some code
}

}

您可以简单地扩展该类

class Extending_class extends WP_some_class
{
    public function preview_handler()
    {
        // Your code
    }
}
请注意,您必须为任何人保留相同的方法参数,在本例中为原始类

从:

[…]扩展类时,子类继承父类的所有公共和受保护方法。除非类重写这些方法,否则它们将保留其原始功能