Extending on a Wordpress Plugin

by Chris   Last Updated May 15, 2018 20:08 PM

I heard you can make a new plugin based off of another one to extend on it. All I want to do is add a few bits of code without editing or deleting anything else. Is my scenario possible (making a new plugin that only extends on the original so not to make edits to the original?

The actual plugin code. The main file when first going into the plugins folder is as follows:

<?php
/**
(
author etc is here)
if ( ! class_exists( 'Inventor' ) ) {

/**
 * Class Inventor
 *
 * @class Inventor
 * @package Inventor
 * @author Pragmatic Mates
 */
final class Inventor {
    const DOMAIN = 'inventor';

    /**
     * Initialize plugin
     */
    public function __construct() {
        $this->constants();
        $this->libraries();
        $this->includes();
        Inventor_Utilities::load_plugin_textdomain( self::DOMAIN, __FILE__ );

        if ( 'SESSION' == apply_filters( 'inventor_visitor_data_destination', INVENTOR_DEFAULT_VISITOR_DATA_STORAGE ) ) {
            add_action( 'init', array(__CLASS__, 'start_session'), 1 );
        }

        add_action( 'activated_plugin', array( __CLASS__, 'plugin_order' ) );
        add_action( 'tgmpa_register', array( __CLASS__, 'register_plugins' ) );
    }

    /**
     * Defines constants
     *
     * @access public
     * @return void
     */
    public function constants() {
        define( 'INVENTOR_DIR', plugin_dir_path( __FILE__ ) );
        define( 'INVENTOR_LISTING_PREFIX', 'listing_' );
        define( 'INVENTOR_LISTING_CATEGORY_PREFIX', 'listing_category_' );
        define( 'INVENTOR_TRANSACTION_PREFIX', 'transaction_' );
        define( 'INVENTOR_REPORT_PREFIX', 'report_' );
        define( 'INVENTOR_USER_PREFIX', 'user_' );
        define( 'INVENTOR_MAIL_ACTION_REPORTED_LISTING', 'REPORTED_LISTING' );
        define( 'INVENTOR_DEFAULT_VISITOR_DATA_STORAGE', 'COOKIE' );

        define( 'INVENTOR_API_ENDPOINT', 'http://inventorwp.com/api/v1/' );
        define( 'INVENTOR_API_VERIFY_URL', INVENTOR_API_ENDPOINT . 'verify/' );
    }

    /**
     * Include classes
     *
     * @access public
     * @return void
     */
    public function includes() {
        if ( apply_filters( 'inventor_database_session_handler_enabled', false ) ) {
            require_once INVENTOR_DIR . 'includes/class-inventor-session-handler.php';
        }
        require_once INVENTOR_DIR . 'includes/class-inventor-scripts.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-template-loader.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-metaboxes.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-post-types.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-field-types.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-taxonomies.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-price.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-widgets.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-filter.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-visitor.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-utilities.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-query.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-shortcodes.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-social.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-billing.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-wire-transfer.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-reports.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-customizations.php';
        require_once INVENTOR_DIR . 'includes/class-inventor-migrations.php';

        // Admin
        if ( is_admin() ) {
            require_once INVENTOR_DIR . 'includes/admin/class-inventor-admin-menu.php';
            require_once INVENTOR_DIR . 'includes/admin/class-inventor-admin-notices.php';
            require_once INVENTOR_DIR . 'includes/admin/class-inventor-admin-updates.php';
            require_once INVENTOR_DIR . 'includes/admin/class-inventor-admin-dashboard.php';
        }
    }

    /**
     * Loads third party libraries
     *
     * @access public
     * @return void
     */
    public static function libraries() {
        require_once INVENTOR_DIR . 'libraries/class-tgm-plugin-activation.php';
        require_once INVENTOR_DIR . 'libraries/cmb_field_map/cmb-field-map.php';
        require_once INVENTOR_DIR . 'libraries/cmb_field_street_view/cmb-field-street-view.php';
    }

    /**
     * Install plugins
     *
     * @access public
     * @return void
     */
    public static function register_plugins() {
        $plugins = array(
            array(
                'name'                  => 'CMB2',
                'slug'                  => 'cmb2',
                'is_automatic'          => true,
                'required'              => true,
                'version'               => '2.2.2.1'
            ),
        );

        tgmpa( $plugins );
    }

    /**
     * Start session
     *
     * @access public
     * @return void
     */
    public static function start_session() {
        session_id() or session_start();
    }

    /**
     * Loads this plugin first
     *
     * @access public
     * @return void
     */
    public static function plugin_order() {
        $wp_path_to_this_file = preg_replace( '/(.*)plugins\/(.*)$/', WP_PLUGIN_DIR.'/$2', __FILE__ );
        $this_plugin = plugin_basename( trim( $wp_path_to_this_file ) );
        $active_plugins = get_option( 'active_plugins' );

        $this_plugin_key = array_search( $this_plugin, $active_plugins );

        if ( $this_plugin_key ) {
            array_splice( $active_plugins, $this_plugin_key, 1 );
            array_unshift( $active_plugins, $this_plugin );
            update_option( 'active_plugins', $active_plugins );
        }
    }
}

new Inventor();

}

There is a second file as well within this plugin. Here is a snippit at the parts I want to addon to a row.php file

<?php $featured = get_post_meta( get_the_ID(), INVENTOR_LISTING_PREFIX . 'featured', true ); ?>
<?php $reduced = get_post_meta( get_the_ID(), INVENTOR_LISTING_PREFIX . 'reduced', true ); ?>

A bunch of code is here

<div class="listing-row <?php if ( $featured ) : ?>featured<?php endif; ?>">
<div class="listing-row-image" style="background-image: url('<?php echo esc_attr( $image ); ?>');">
    <a href="<?php the_permalink() ?>" class="listing-row-image-link"></a>

    <div class="listing-row-actions">
        <?php do_action( 'inventor_listing_actions', get_the_ID(), 'row' ); ?>
    </div><!-- /.listing-row-actions -->

    <?php if ( $featured ) : ?>
        <div class="listing-row-label-top listing-row-label-top-left"><?php echo esc_attr__( 'Featured', 'inventor' ); ?></div><!-- /.listing-row-label-top-left -->
    <?php endif; ?>

     <?php if ( $pink ) : ?>
        <div class="listing-row-label-top listing-row-label-top-left"><?php echo esc_attr__( 'Pink', 'inventor' ); ?></div><!-- /.listing-row-label-top-left -->
    <?php endif; ?>

    <?php if ( $reduced ) : ?>
        <div class="listing-row-label-top listing-row-label-top-right"><?php echo esc_attr__( 'Reduced', 'inventor' ); ?></div><!-- /.listing-row-label-top-right -->
    <?php endif; ?>

    <?php $listing_type_name = Inventor_Post_Types::get_listing_type_name(); ?>
    <?php if ( ! empty( $listing_type_name ) ) : ?>
        <div class="listing-row-label-bottom"><?php echo wp_kses( $listing_type_name, wp_kses_allowed_html( 'post' ) ); ?></div><!-- /.listing-row-label-bottom -->
    <?php endif; ?>
</div><!-- /.listing-row-image -->

Now then, what i want to do is in a new plugin to extend off of this is add in these 2 parts to my own plugin file.

    <?php $gold = get_post_meta( get_the_ID(), INVENTOR_LISTING_PREFIX . 'gold', true ); ?>

at the top. and then

    <?php if ( $gold ) : ?>
        <div class="listing-row-label-top listing-row-label-top-left"><?php echo esc_attr__( 'Gold', 'inventor' ); ?></div><!-- /.listing-row-label-top-left -->
    <?php endif; ?>

which will be placed in the div class="listing-row-actions">' section

So is there a way to make a plugin extension kind of thing so I do not make edits to the original plugin

Tags : plugins


Related Questions


Change default url to plugin custom post type

Updated May 25, 2016 08:03 AM

Change from blogger to wordpress

Updated April 03, 2017 09:08 AM

Keeping mu-plugin updated from GitHub

Updated April 11, 2017 10:08 AM

How to update mu-plugin

Updated October 08, 2018 16:08 PM

blog info can not found file path

Updated March 26, 2015 07:24 AM