how to extend specific method in a child class

i m not very good with oop but know little bit of it.

Well i am trying to extend a class.. actually i want to add some additional functionality to class method…

Read More

This is the class, I am trying to extend

https://github.com/tammyhart/Reusable-Custom-WordPress-Meta-Boxes/blob/master/metaboxes/meta_box.php

with the following code in save_box() method

if ( ! wp_is_post_revision( $post_id ) && 'testimonials' == get_post_type( $post_id ) ) {
    remove_action( 'save_post', 'testimonials_save_post' );

    wp_update_post( array(
        'ID' => $post_id,
        'post_title' => 'Testimonial - ' . $post_id
    ) );

    add_action( 'save_post', 'testimonials_save_post' );
}

Related posts

Leave a Reply

1 comment

  1. It’s a matter of instantiating the child class which contains only the new method. Considering the sample file:

    include_once( 'meta_box.php' ); // ORIGINAL
    include_once('my-class.php');   // CHILD
    
    // Instantiate the Child Class
    $sample_box = new My_Custom_Add_Meta_Box( 'sample_box', 'Sample Box', $fields, 'post', true );
    

    And my-class.php would contain:

    class My_Custom_Add_Meta_Box extends Custom_Add_Meta_Box {
        /**
         * saves the captured data
         */
        function save_box( $post_id ) {
            wp_die('Child class save method called.');
            # do_something();
        }
    }