• Resolved adminbergtourentipptirol

    (@adminbergtourentipptirol)


    Hi,

    Regarding my previous unresolved topic I want to ask you again for a solution?

    I want to define e.g. 3 brave popups and want to display one of them (in a random order), when the visitor opens a blog page every week. At the moment I can only assign one of these popups to be opened for blog posts. If I would assign all 3 popups to be opened for blog Posts, the visitor will see all of the 3 popups behind each other.

    The best solution for me would be a developer filter where I can decide on my own. As I see in your Docs you only have one topic in the developer section (opening/closing dynamically). Do you have any developer hooks in your plugin?

    Best regards,
    Dominik

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Brave

    (@getbrave)

    @adminbergtourentipptirol There is a bravepop_before_render hook which holds all the popups in your site. Its fired just before filtering and rendering your brave popups.

    The hook contains an array of popup items. Just like this:

    [{"type":"popup","id":257,"status":"draft","exclude":{}},{"type":"popup","id":436,"status":"draft","exclude":{}}]

    What you can do is, first publish all 3 popups.

    And then access the popup array list and keep the one that you want to render and remove the other 2 from the array based on your random logic.

    add_action( 'bravepop_before_render', 'my_brave_popups_override');
    function my_brave_popups_override($array) {
       $popupIDs = [333, 323, 432]; //change these 3 numbers with your popup ids. Can be viewed in the address bar when editing in the backend
       $randomItem = array_rand( $popupIDs, 1 ); //Selects a random popup id from all 3 popup ids.
       $excludedItems = array_diff($popupIDs, [$randomItem]); //extracts the ids that were not selected. 
    
       $newFilteredArray = [];
    
       //loop through the all the popups and excluded the 2 popups that were not selected to be displayed 
       foreach ($array as $key => $item) {
          if($item->ID !== $excludedItems[0] && $item->ID !== $excludedItems[0]){
             $newFilteredArray[] = $item;
          }
       }
    
       return $newFilteredArray;
    }
    Thread Starter adminbergtourentipptirol

    (@adminbergtourentipptirol)

    Hi @getbrave,

    Thanks for your quick response.

    I just tried your code snippet, but unfortunately it isn´t working as expected. As I can see in the plugin coding there is no array defined as an input parameter for the action bravepop_before_render.
    do_action( 'bravepop_before_render' );

    Therefore I get this for the array of your function:
    string(0) ""

    Could it be that you meant the other action (bravepop_after_render)?
    do_action( 'bravepop_after_render', array($filtered_popups) );

    Another question: Do you have a list/documentation of all available developer action/hooks?

    Best regards,
    Dominik

    Plugin Author Brave

    (@getbrave)

    Dominik,

    Looks like a bug. Can you please all the code of the render.php file with the one you find in this page: https://haste.zneix.eu/raw/detehohedo

    Thanks

    Thread Starter adminbergtourentipptirol

    (@adminbergtourentipptirol)

    Hi @getbrave,

    I just updated my Brave plugin to the newest version and the code in render.php still is the same regarding the before render action:

    /**
     * Popup Renderer
     * Finds the Popup assigned to current page and renders it.
    **/
    
    add_action('wp_head', 'bravepop_render_popup', 9);
    function bravepop_render_popup() {
       $brave_popupID = filter_input(INPUT_GET, 'brave_popup');
       $brave_popupStep = filter_input(INPUT_GET, 'popup_step');
    
       do_action( 'bravepop_before_render' );
       //Popup Preview
       if($brave_popupID && is_user_logged_in()){ 
          return new BravePop_Popup( $brave_popupID, 'popup', true, $brave_popupStep  ? absint($brave_popupStep) : false); 
       }
    
       //Bail if is Customizing the Website from Appearance > Customize or with Elementor
       $is_elemntor_page_editor = filter_input(INPUT_GET, 'elementor-preview');
       if(is_customize_preview() || isset($is_elemntor_page_editor)){
          return;
       }
    
       $filtered_popups = bravepop_get_current_page_popups();
       //error_log(json_encode($filtered_popups));
       if($filtered_popups &...

    Can you please tell me what’s the reason for it?

    Best regards,
    Dominik

    Plugin Author Brave

    (@getbrave)

    Its because we did not update the plugin yet. It will take a few weeks to release the next update. For now, you will have to modify your current render.php file using the one I posted above to patch the bug.

    Regards

    Thread Starter adminbergtourentipptirol

    (@adminbergtourentipptirol)

    Hi @getbrave,

    OK, I updated my code to get your newest version, but unfortunately it isn’t working because this is an action hook where I can’t return any parameter or array. Shouldn’t it be a filter hook to return the array back to your standard coding?

    Best regards,
    Dominik

    Plugin Author Brave

    (@getbrave)

    @adminbergtourentipptirol You are correct. The updated code for render.php I sent you has an issue. Kindly replace the code of render.php file and your code should work:

    https://haste.zneix.eu/raw/uwehybeqaf

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Possibility to group popups’ is closed to new replies.