Plugins: What is the correct/safest method of editing plugins?

Hi,
1.A very simple question from a newbie. We are running Multisite and wish to change the MP Product Listing .php slightly.

What is the correct way of editing plugin files? Just edit marketpress.php directly and make a note of our changes in case we upgrade the plugin? Then when upgrading, upgrade the plugin on the development server first and test before release?

Or do we copy the marketpress.php file, call it the same name and add it to our twentyeleven child theme?

2. I'm not understanding your theme permissions instructions. Our child theme lives in wp-content/themes. Your instructions are "save your css file with the "MarketPress Theme: NAME" header in the "/marketpress/css/themes/" folder. Er...huh? If our theme folder is called ourtheme, are you saying we rename it something else (what?) and chuck it in the folder you mention? After we do that, can we safely ignore it there? It's only there so that it will show up automatically for other sites to install?

Thanks!

  • aecnu

    Greetings cowontherun,

    A very simple question

    Indeed some of the very longest and hardest threads in this community started out with a statement like this .... lol

    What is the correct way of editing plugin files?

    This is your call, personally I use ssh making direct modifications on the production server.

    The absolute right answer is the one that works best for you while at the same time accomplishing the mission.

    Just edit marketpress.php directly and make a note of our changes in case we upgrade the plugin?

    That sounds like a wise move or archive the modified version of the file on your computer for quick FTP replacement if deemed necessary.

    Then when upgrading, upgrade the plugin on the development server first and test before release?

    Once again, the absolute right answer is the one that works best for you while at the same time accomplishing the mission.

    Or do we copy the marketpress.php file, call it the same name and add it to our twentyeleven child theme?

    What Twenty Eleven child theme? Did you create one? I just checked and Twenty Eleven does not come with a child theme hierarchy therefore I ask the two previous questions.

    2. I'm not understanding your theme permissions instructions. Our child theme lives in wp-content/themes. Your instructions are "save your css file with the "MarketPress Theme: NAME" header in the "/marketpress/css/themes/" folder. Er...huh? If our theme folder is called ourtheme, are you saying we rename it something else (what?) and chuck it in the folder you mention? After we do that, can we safely ignore it there? It's only there so that it will show up automatically for other sites to install?

    I believe the whole problem with this above question and included sub questions is referring to a child theme that does not exist.

    Information on child themes is here.

    Please advise if you have indeed created a child theme for Twenty Eleven?

    Thank you for being a WPMU Dev Member!

    Cheers, Joe

  • cowontherun

    Hi Joe,

    Yep I have created a child theme of Twenty Eleven and I have a few php files in my child theme folder such as header.php.

    My question/s more clearly are;

    1.If I want to edit the php of the global category list, would I create a file called mp_global_category_list.php , put it in my child theme folder, and just pop the new functions into that? Because I tried that but the parent marketplace-ms.php file still took preference. So now I am editing Marketpress .php directly but this is dangerous if I one day upgrade.

    2. I don't understand clearly the Theme permissions section of the Network Admin screen. I take it that MarketPress Theme: NAME" header means the header within the .css file that describes the css for Wordpress? Are these Theme permission instructions relevant for child themes of themes other than MarketPress? It sounds like these are Market press Child theme specific instructions.

    Thanks for your help! Market press is an awesome plugin.

  • aecnu

    Greetings cowontherun,

    Thank you for the great questions!

    1.If I want to edit the php of the global category list, would I create a file called mp_global_category_list.php , put it in my child theme folder, and just pop the new functions into that? Because I tried that but the parent marketplace-ms.php file still took preference. So now I am editing Marketpress .php directly but this is dangerous if I one day upgrade.

    It is my opinion what you should have done in this specific case weas copy the parent marketplace-ms.php file into the child theme and your modifications should be safe and the file in the child theme should be used and acknowledged by Market Press.

    2. I don't understand clearly the Theme permissions section of the Network Admin screen. I take it that MarketPress Theme: NAME" header means the header within the .css file that describes the css for Wordpress? Are these Theme permission instructions relevant for child themes of themes other than MarketPress?

    It sounds like these are Market press Child theme specific instructions.

    You are spot on concerning this one that they are parent theme/child theme instructions.

    Please advise if the answer of copying the file to the child and modifications made to the file in the child take precedence.

    Cheers, Joe

  • aristath

    I follow a different approach...
    If you open the file mp_global_category_list.php, you'll notice that the main content of the page is rendered using this code:

    <?php echo framemarket_page_title_output(); ?></h1>
    <?php
    if ( $slug = get_query_var('global_taxonomy') ) {
    $args = array();
    $args['echo'] = false;
    $args['category'] = $slug;
    //check for paging
    if (get_query_var('paged'))
    $args['page'] = intval(get_query_var('paged'));
    $content = framemarket_mp_list_global_products( $args );
    $content .= get_posts_nav_link();
    } else { //no category set, so show list
    $content .= mp_global_categories_list( array( 'echo' => false ) );
    }
    echo $content;
    ?>

    I edit my theme replacing framemarket_mp_list_global_products with custom_list_global_products and mp_global_categories_list with custom2_global_categories_list.

    Then, open the file framemarket/library/marketpress.php and copy the whole function framemarket_mp_list_global_products section to your theme's functions.php file. rename it to custom_list_global_products and now you're free to change and alter whatever you want without altering a single line from framemarket. Simply edit your own files.

    Most functions starting with mp_.... are in the file marketpress-includes/template-functions.php in your marketpress core.
    So grab the function called mp_global_categories_list from that file, copy-paste it inside your theme's functions.php again, change it's name and start altering the code to suit your own needs.

    Note: renaming the functions after copying them to your functions.php file is VERY important. If you don't, you'll get a blank screen.

    I find this method to be A LOT better than simply slashing and hacking my plugins and themes... And it's better on the long run since updates are a lot simpler this way.
    If you hack a plugin or theme, then every time an update is available you'll have to diff the changes and re-apply them manually!!!

  • cowontherun

    Excellent information Aristath and aecnu thanks.

    Neither method work, the parent still takes preference. These are:
    1. Just copy marketpress-ms.php into child theme (aecnu)
    2. Copy a function, paste into functions.php of child theme, and rename the mp_ prefix to custom_ (aristath)

    I'm not using either the Framemarket theme or a child of the Framemarket theme (so I don't have a mp_global_category_list.php file). I'm using a child theme of Twenty Eleven.

    However, I'm going to download Framemarket, create a child of it, and copy my CSS over as I seem to be running into other problems not using Framemarket ie. Add to Cart button not showing in Product Lists.

    Any more advice you can give me as to the above problem is appreciated.

  • cowontherun

    Am using Framemarket theme but I am still unable to override the Marketpress plugin php files. As an example, in this file: Plugins > Marketpress > Marketpress.php, I want to override the following code so that no More info link shows on an excerpt.

    `//replaces wp_trim_excerpt in our custom loops
    function product_excerpt($excerpt, $content, $product_id) {
    $excerpt_more = ' ' . __('More Info »', 'mp') . '';
    if ($excerpt) {
    return $excerpt . $excerpt_more;
    } else {
    $text = strip_shortcodes( $content );
    //$text = apply_filters('the_content', $text);
    $text = str_replace(']]>', ']]>', $text);
    $text = strip_tags($text);
    $excerpt_length = apply_filters('excerpt_length', 55);
    $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
    if ( count($words) > $excerpt_length ) {
    array_pop($words);
    $text = implode(' ', $words);
    $text = $text . $excerpt_more;
    } else {
    $text = implode(' ', $words);
    }
    }
    return $text;
    }'

    If I copy the function and paste into my child theme root folder into functions.php, the child code does not override the original. I have tried adding various solutions such as childtheme_override and remove_action/add_action instructions and renaming the function, all to no avail.

  • cowontherun

    WPMU's own instructions on your Framemarket Child Theme page says to move the child theme to be a sibling of Framemarket after install, NOT to keep a copy of it in the Framemarket Themes folder.

    Inside wp-content/themes/framemarket you’ll see another directory entitled themes with a gridmarket folder. Move this folder to the same wp-content/themes directory to match framemarket as shown below

    Even if I duplicate the child theme by keeping a copy of the child in the Framemarket Themes folder, this does not resolve the issue. The function in my child theme functions.php does not overwrite the function in the parent marketpress.php file.

    Any other ideas?

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.