Help with functionality of a customized plugin

Hi All,

This is my first time asking for help here so please bear with me. I am currently stuck trying to add some custom functionality to an up to date WP install, running the Divi Theme, and trying to customize the results of the “Favorites” plugin. I’m working locally off of MAMP, using a simple child theme, and overwriting a specific Divi gallery class in order to add a favorites button to each image within a gallery.

I had some help with the logic of this solution, and now find myself over my head again. My goal is to allow users to favorite images within the galleries (and ultimately for that data to be accessible to the user); the plugin I’m using functions properly with it’s specified “posttypes”, however in order to gain functionality with the Galleries, I needed to overwrite the “Gallery.php” module within my child-theme. I have added this line:

$output .= get_favorites_button( $id );

This has been placed within the render function of the class. The buttons are indeed being output for each image in the gallery, however they do not all function, only the 1st and 4th in the first row of the gallery, but after that only 1 or 2 random buttons function (without any pattern I can see) on any gallery I make. Within the plugin settings I have to enable Favorites for “Pages” on the “Display & Post Types” tab. I suspect my logic is flawed with the “$id” variable that I am using, and that I should be using a different attribute/property of the images to get a unique button for each image but I am not sure.

The console in Chrome/Canary gives this message for the buttons that work:

  1. {status: “success”, favorite_data: {…}, favorites: Array(1)}

  2. favorite_data: {id: 3, siteid: 1, status: “active”, groupid: 1, save_type: “cookie”}

And this message for the buttons that don’t:

  1. {status: “error”, message: “Invalid post.”}

  2. message: “Invalid post.”

  3. status: “error”

I’m also not sure on how to ask this question and provide you guys with the information needed to answer it. The Gallery.php function that I am overwriting is around 625 lines long, and that seems long to post here, especially since the only piece of code I am adding to it is the piece above that is posted at line 594. I recognize that it’s probably near impossible to answer this without seeing more code or examples, so please ask away and I will try to accommodate; since the development is being done locally with MAMP I am not sure how I can show it to everyone here, but I am willing to do whatever is asked as far as providing any information to help shed some light on a solution for this.

Thanks for reading and any help that can be offered will be most appreciated!

Youch! Dang…It’s pretty sad when a “deleted post” has twice the views as a real question. Anyone?

After looking in the codex regarding the add_action hook, I am wondering if I have used the wrong syntax for that hook call…?

The codex states:
Using with a Class
To use add_action() when your plugin or theme is built using classes, you need to use the array callable syntax. You would pass the function to add_action() as an array, with $this as the first element, then the name of the class method, like so:

/**

  • Class WP_Docs_Class.
    */
    class WP_Docs_Class {

    /**

    • Constructor
      */
      public function __construct() {
      add_action( ‘save_post’, array( $this, ‘wpdocs_save_posts’ ) );
      }

The function that I use in my functions.php to hook my custom “gallery” is:

// Divi-child Custom Favorites Solution Functions file
/================================================ #Load custom Divi module ================================================/
function customize_divi_modules() {
//Exit if Divi is not loaded
if( ! class_exists(‘ET_Builder_Module’)) {
return;
}
//Get the custom Gallery Module file
get_template_part(“custom-modules/Custom”);
//Create the new Custom Gallery class, based on the original Gallery class
$custom_module = new Custom_Module_Gallery();
remove_shortcode( ‘et_pb_gallery’ );
add_shortcode( ‘et_pb_gallery’, array($custom_module, ‘_render’) );
}
add_action( ‘wp’, ‘customize_divi_modules’, 9999 );

Because I the output statement that I added to the “render” function, is within a class (in the “Custom.php” file which I am using to overwrite the original Divi Gallery.php file), does this mean my output statement:

$output .= get_favorites_button( $id );

is using incorrect syntax?

Any tips, ideas or suggestions? Please and thank you~

Sponsor our Newsletter | Privacy Policy | Terms of Service