mmarquiscreative / agx-hearing-test

MIT License
1 stars 0 forks source link

wp_filter for test #7

Closed mmarquiscreative closed 6 years ago

mmarquiscreative commented 6 years ago

@see8ch Hey, so we have things built right now so that the test is loaded via the wp footer filter, but set to display none, and there is an event listener in the app.js that looks for a click event on a element with an #OHQ_Button_Start, which toggles the display to block.

However in talking with Austin, it looks like we only want it to load on certain pages. We've tried having it entirely as a shortcode, which can just be placed on the page somewhere, but we run into some weird z-index issues because of how the AGX Hearing site is structured, which prevents us from escaping the level of z-index scope we need to get on top of everything.

So is there a way to use wp footer hook, but only on pages where another filter or action fires first? (like can we do a apply_filter or do_action from within another filter or action? And then not have the wp footer filter apply until the parent filter or action catches the hook?)

Basically we're trying to avoid having it load in every footer on every page load.

mmarquiscreative commented 6 years ago

Ok, think I figured something out.

function agx_OHQ_Button($content) {
    add_filter('wp_footer', 'agx_hearing_test');

    echo '<div>
   <button id="OHQ_Start_Btn" onclick="AGX_OHQ_toggleClass()" >Start Quiz</button>
   </div>';
};

add_shortcode( 'OHQ_Button', 'agx_OHQ_Button' );
see8ch commented 6 years ago

Did the solution above work? If not you could build an option that displays on the WP admin view for each page and give the user the option to toggle on/off.

mmarquiscreative commented 6 years ago

@see8ch Yeah! That ended up working. Thankfully the simplest solution worked. Whew.