• I have a theme on WordPress called A and his child called A-child.

    On A child I have on A/includes/projects.php a class called project and I want to redifend one method inside this class called method1().

    First that I tried is to re-create the same structured on A-child theme : A-child/includes/projects.php and on functions.php put the require_once but the site crashed. Without the require_once nothing happens.

    The other thing that I tried is to redifined the method1() on functions.php and no luck, nothing happens again. I thought obvious, but no one knows.

    EDIT:

    I need that when on the A Theme call $project->method1(); execute the method1() redefined on my A-child Theme.

    I only need to add one line but the parent theme has updated option and I don’t want to re write the same line everytime that I update it.

    Moreover the method1() don’t have any do_action in order to be rewrite on functions.php.

    PD: The method1() is called with add_ajax() I don’t know if it is usefull for us.

    Any help?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    How is that class used? Follow the breadcrumbs until you find the thing calling it, then override that to do your own thing (load your own class).

    Thread Starter imazzara

    (@imazzara)

    The class is used to create a project and if is OK the method1() return the ajax call.

    Because of that I need to redefined the method1() because I need the some vars that has value inside this method.

    I don’t know if I’ve been clear of what I need to do.

    On the method1() there is :

    if ($this->disable_plan && $request[‘method’] == ‘create’) {

    // disable plan, free to post place
    $response = array(
    ‘success’ => true,
    ‘data’ => array(

    // set redirect url
    ‘redirect_url’ => $result->permalink
    ) ,
    ‘msg’ => __(“Submit place successfull.”, ET_DOMAIN)
    );

    // send response
    wp_send_json($response);
    }

    I need to add one line after the wp_send_json($response) because I need some $request and $this stuffs

    Thread Starter imazzara

    (@imazzara)

    Extend:

    On the contrusct of the class I have :

    class MyClass extends ANOTHERCLASS
    {
    function __construct($post_type = ‘project’) {
    $this->mail = new Fre_Mailing();
    $this->post_type = PROJECT;
    $this->disable_plan = ae_get_option(‘disable_plan’, false);
    $this->add_ajax(‘ae-fetch-projects’, ‘fetch_post’);
    $this->add_ajax(‘ae-project-sync’, ‘post_sync’); // post_sync is my method1()

    }
    }

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘WordPress redefine class or class method on child theme’ is closed to new replies.