Plugin Directory

Changeset 1858944


Ignore:
Timestamp:
04/16/2018 09:45:22 AM (8 years ago)
Author:
Deftly
Message:

Updating with Tonya Mork's refactoring

Location:
beans-visual-hook-guide/trunk
Files:
29 added
2 edited

Legend:

Unmodified
Added
Removed
  • beans-visual-hook-guide/trunk/beans-visual-hook-guide.php

    r1840700 r1858944  
    11<?php
    2 /*
    3 Plugin Name: Beans Visual Hook Guide
    4 Plugin URI: https://github.com/JeffCleverley/Beans-Visual-Hook-Guide
    5 Description: Find Beans Hooks (HTML API created action hooks only at the moment) quickly and easily by seeing their actual locations inside your theme.
    6 Version: 1.0.0
    7 Author: Jeff Cleverley
    8 Author URI: https://learningcurve.xyz
    9 Text Domain: beans-visual-hook-guide
    10 License: GPLv2
     2/**
     3 * Loads the Beans Visual Hook Guide plugin.
     4 *
     5 * @package    LearningCurve\BeansVisualHookGuide
     6 * @since      1.1.0
     7 * @author     Jeff Cleverley
     8 * @link       https://learningcurve.xyz
     9 * @license    GNU-2.0+
     10 *
     11 * @wordpress-plugin
     12 * Plugin Name:     Beans Visual Hook Guide
     13 * Plugin URI:      https://github.com/JeffCleverley/Beans-Visual-Hook-Guide
     14 * Description:     Find Beans Hooks (HTML API created action hooks only at the moment) quickly and easily by seeing
     15 * their actual locations inside your theme.
     16 * Version:         1.1.0
     17 * Author:          Jeff Cleverley
     18 * Author URI:      https://learningcurve.xyz
     19 * License URI:     https://www.gnu.org/licenses/gpl-2.0.html
     20 * Text Domain:     beans-visual-hook-guide
     21 * Requires WP:     4.6
     22 * Requires PHP:    5.6
     23 */
    1124
    12 This plugin was inspired by Christopher Cochran's Genesis Visual Hook Guide, one of my favourite plugins for Genesis Development.
    13 I started with his plugin and went from there.... Thank you very much Christopher!
    14 https://genesistutorials.com/visual-hook-guide/
    15 https://github.com/christophercochran/Genesis-Visual-Hook-Guide
    16 http://christophercochran.me
    17 */
     25/**
     26 * Special thanks to:
     27 *
     28 * This plugin was inspired by Christopher Cochran's Genesis Visual Hook Guide, one of my favourite plugins for
     29 * Genesis Development. I started with his plugin and went from there.... Thank you very much Christopher!
     30 *
     31 * Links to Christopher:
     32 * - https://genesistutorials.com/visual-hook-guide/
     33 * - https://github.com/christophercochran/Genesis-Visual-Hook-Guide
     34 * - http://christophercochran.me
     35 */
     36
     37namespace LearningCurve\BeansVisualHookGuide;
    1838
    1939if ( ! defined( 'ABSPATH' ) ) {
     
    2141}
    2242
    23 define( 'BVHG_BEANS_FLAVOURS', array( 'beans', 'tm-beans' ) );
    24 define( 'BVHG_BEANS_PLUGIN_URL', plugins_url( null, __FILE__ ) );
    25 
    26 register_activation_hook( __FILE__, 'bvhg_environment_check' );
    27 add_action( 'switch_theme', 'bvhg_environment_check' );
    2843/**
    29  * Check active theme is Beans:
    30  * 1. Before Activation
    31  * 2. After Switching Themes
     44 * Gets this plugin's absolute directory path.
    3245 *
    33  * If not:
    34  * 1. Don't allow activation and throw a die message
    35  * 2. Disable plugin
     46 * @since  1.0.0
     47 * @ignore
     48 * @access private
     49 *
     50 * @return string
    3651 */
    37 function bvhg_environment_check() {
    38 
    39     $is_beans          = in_array( wp_get_theme()->Template, BVHG_BEANS_FLAVOURS );
    40     $deactivate_plugin = deactivate_plugins( plugin_basename( __FILE__ ) );
    41 
    42     if ( ! $is_beans && current_filter() != 'switch_theme' ) {
    43         $deactivate_plugin;
    44         wp_die( 'Sorry, you can\'t activate unless you have installed Beans</a>' );
    45     } elseif ( ! $is_beans ) {
    46         require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    47         $deactivate_plugin;
    48     }
     52function _get_plugin_directory() {
     53    return __DIR__;
    4954}
    5055
    51 add_action( 'admin_notices', 'bvhg_active_notice' );
    5256/**
    53  * Notices to display when plugin active:
    54  * Notice 1 - Displays when Development Mode isn't active, but plugin is.
    55  * Notice 2 - Displays when Development Mode and Plugin are active.
     57 * Gets this plugin's URL.
     58 *
     59 * @since  1.1.0
     60 * @ignore
     61 * @access private
     62 *
     63 * @return string
    5664 */
    57 function bvhg_active_notice() {
     65function _get_plugin_url() {
     66    static $plugin_url;
    5867
    59     if ( ! _beans_is_html_dev_mode() ) {
    60         echo '<div class="notice notice-error" ><p>';
    61         echo sprintf(
    62                 __(
    63                     'Beans Visual Hook Guide is currently installed, but it also requires <a href="%s">Development</a> mode to be active before it can be enabled on the toolbar.',
    64                     'beans-visual-hook-guide'
    65                 ),
    66                 esc_url( get_site_url() . '/wp-admin/themes.php?page=beans_settings' ) );
    67         echo '</p></div>';
    68     } else {
    69         echo '<div class="notice notice-warning" >'; ?>
    70         <p><?php _e( 'Beans Visual Hook Guide and Development mode are both active. If this is a production site, remember to deactivate both after use.', 'beans-visual-hook-guide' ) ?></p><?php
    71         echo '</div>';
     68    if ( empty( $plugin_url ) ) {
     69        $plugin_url = plugins_url( null, __FILE__ );
    7270    }
     71
     72    return $plugin_url;
    7373}
    7474
    75 add_action( 'admin_bar_menu', 'bvhg_toolbar_top_level_links', 100 );
     75register_activation_hook( __FILE__, __NAMESPACE__ . '\deactivate_when_beans_not_activated_theme' );
     76add_action( 'switch_theme', __NAMESPACE__ . '\deactivate_when_beans_not_activated_theme' );
    7677/**
    77  * Add the Admin Toolbar Top Level Link conditionally:
    78  * 1. Execute function to add Link to Beans Theme Settings if Development mode is inactive.
    79  * 2. Execute function to enable Visual Guide if Development mode is active.
    80  * 3. Execute function to add Visual Guide Top level link if Visual Guide is enabled.
     78 * If Beans is not the activated theme, deactivate this plugin and pop a die message when not switching themes.
     79 *
     80 * @since 1.0.0
     81 *
     82 * @return void
    8183 */
    82 function bvhg_toolbar_top_level_links() {
    83 
    84     if ( is_admin() ) {
     84function deactivate_when_beans_not_activated_theme() {
     85    // If Beans is the active theme, bail out.
     86    $theme = wp_get_theme();
     87    if ( in_array( $theme->template, array( 'beans', 'tm-beans' ), true ) ) {
    8588        return;
    8689    }
    8790
    88     $toolbar_top_link_args = array(
    89         'development_mode_disabled' => array(
    90             'id'    => 'bvhg_hooks',
    91             'title' => __( 'Beans Visual Hook Guide requires development mode to be enabled!', 'beans-visual-hook-guide' ),
    92             'href'  => esc_url( get_site_url() . '/wp-admin/themes.php?page=beans_settings' ),
    93         ),
    94         'enable_visual_hook_guide'  => array(
    95             'id'    => 'bvhg_hooks',
    96             'title' => __( 'Enable Beans Visual Hook Guide', 'beans-visual-hook-guide' ),
    97             'href'  => esc_url( add_query_arg( 'bvhg_enable', 'show' ) ),
    98         ),
    99         'add_visual_hook_guide'     => array(
    100             'id'    => 'bvhg_html',
    101             'title' => __( 'Beans Visual Hook Guide', 'beans-visual-hook-guide' ),
    102             'href'  => '',
    103         ),
    104     );
     91    deactivate_plugins( plugin_basename( __FILE__ ) );
    10592
    106     if ( ! _beans_is_html_dev_mode() ) {
    107         bvhg_add_toolbar_top_link( $toolbar_top_link_args['development_mode_disabled'] );
    108 
    109         return;
    110     }
    111 
    112     if ( 'show' != isset( $_GET['bvhg_enable'] ) ) {
    113         bvhg_add_toolbar_top_link( $toolbar_top_link_args['enable_visual_hook_guide'] );
    114     } elseif ( 'show' == isset( $_GET['bvhg_enable'] ) ) {
    115         bvhg_add_toolbar_top_link( $toolbar_top_link_args['add_visual_hook_guide'] );
     93    if ( current_filter() !== 'switch_theme' ) {
     94        $message = __( 'Sorry, you can\'t activate this plugin unless the <a href="https://www.getbeans.io" target="_blank">Beans</a> framework is installed and a child theme is activated.', 'beans-visual-hook-guide' );
     95        wp_die( wp_kses_post( $message ) );
    11696    }
    11797}
    11898
    11999/**
    120  *  Function to add Beans Visual Hook Guide Top level links
     100 * Autoload the plugin's files.
    121101 *
    122  * 1. Generate link to Beans Setting if Development mode is disabled
    123  * 2. Generate a link to enable Beans Visual Hook Guide
    124  * 3. Generate Top Level Menu for configuration drop-downs
     102 * @since 1.1.0
    125103 *
    126  * @param $menu_args    array   values to generate the required link.
     104 * @return void
    127105 */
    128 function bvhg_add_toolbar_top_link( $menu_args ) {
    129 
    130     global $wp_admin_bar;
    131 
    132     $wp_admin_bar->add_node(
    133         array(
    134             'id'       => $menu_args['id'],
    135             'title'    => $menu_args['title'],
    136             'href'     => $menu_args['href'],
    137             'position' => 0,
    138         )
    139     );
    140 }
    141 
    142 add_action( 'admin_bar_menu', 'bvhg_toolbar_second_level_link_prep', 101 );
    143 /**
    144  * Add the Admin Toolbar 2nd Level Links - to appear in drop-down:
    145  * 1. Execute function to show all possible HTML Hooks in a Submenu to allow them to be selected individually.
    146  * 2. Execute function to show all possible HTML hooks on screen at once (Crazy Mode).
    147  * 3. Execute function to clear the display of all currently selected hooks.
    148  * 4. Execute function to disable Visual Hook guide and clear the display of all currently selected hooks.
    149  */
    150 function bvhg_toolbar_second_level_link_prep() {
    151 
    152     $markup_array_query_args = get_transient( 'beans_html_markup_transient' );
    153 
    154     if ( ! $markup_array_query_args ) {
    155         return;
    156     }
    157 
    158     $bvhg_main_query_args = array(
    159         'bvhg_html_hooks',
    160         'bvhg_enable',
    161         'bvhg_enable_every_html_hook'
     106function autoload_files() {
     107    $files = array(
     108        'markup/handler.php',
     109        'admin/admin-bar.php',
     110        'admin/notices.php',
     111        'asset/ajax.php',
     112        'asset/handler.php',
     113        'plugin.php',
    162114    );
    163115
    164     global $markup_array_query_args_stripped;
    165 
    166     bvhg_strip_markup_query_args_of_square_brackets( $markup_array_query_args );
    167 
    168     $bvhg_query_args_to_clear = array_merge( $markup_array_query_args_stripped, $bvhg_main_query_args );
    169 
    170     $markup_array_query_args_stripped[] = 'bvhg_enable_every_html_hook';
    171 
    172     bvhg_toolbar_second_level_link_arg_generation( $bvhg_query_args_to_clear );
    173 }
    174 
    175 /**
    176  * Create a multidimensional array of all the args required to add the admin nodes,
    177  * then loop through them and execute a function with each arg array passed.
    178  *
    179  * @param $bvhg_query_args_to_clear     array   Query args array to be used to clear the display
    180  */
    181 function bvhg_toolbar_second_level_link_arg_generation( $bvhg_query_args_to_clear ) {
    182 
    183     global $markup_array_query_args_stripped;
    184 
    185     $toolbar_drop_down_links_args = array(
    186         'html_list'     => array(
    187             'id'    => 'bvhg_html_list',
    188             'title' => __( 'All HTML API Hooks List - Show Individually', 'beans-visual-hook-guide' ),
    189             'href'  => '',
    190         ),
    191         'show_all'      => array(
    192             'id'    => 'bvhg_show_all_html',
    193             'title' => __( 'Show ALL HTML API Hooks (Crazy Mode)', 'beans-visual-hook-guide' ),
    194             'href'  => esc_url( add_query_arg( 'bvhg_enable_every_html_hook', 'show' ) ),
    195         ),
    196         'clear'         => array(
    197             'id'    => 'bvhg_html_clear',
    198             'title' => __( 'Clear all displayed Hooks', 'beans-visual-hook-guide' ),
    199             'href'  => esc_url( remove_query_arg( $markup_array_query_args_stripped ) ),
    200         ),
    201         'clear_disable' => array(
    202             'id'    => 'bvhg_html_clear_disable',
    203             'title' => __( 'Disable Beans HTML API Visual Hook Guide', 'beans-visual-hook-guide' ),
    204             'href'  => esc_url( remove_query_arg( $bvhg_query_args_to_clear ) ),
    205         )
    206     );
    207 
    208     foreach ( $toolbar_drop_down_links_args as $toolbar_drop_down_links_arg ) {
    209         bvhg_toolbar_generate_second_level_links( $toolbar_drop_down_links_arg );
     116    foreach ( $files as $file ) {
     117        require __DIR__ . '/src/' . $file;
    210118    }
    211119}
    212120
    213121/**
    214  * Function to strip the square brackets from the markup array,
    215  * So the array can be used to generate query args.
     122 * Launch the plugin.
    216123 *
    217  * Once stripped they are added to a global array.
     124 * @since 1.1.0
    218125 *
    219  * @param $markup_array_query_args  array   array of all HTML API data-markup-id scraped from the DOM
     126 * @return void
    220127 */
    221 function bvhg_strip_markup_query_args_of_square_brackets( $markup_array_query_args ) {
    222 
    223     global $markup_array_query_args_stripped;
    224 
    225     foreach ( $markup_array_query_args as $markup_array_query_arg ) {
    226         $markup_array_query_arg_first_strip = str_replace( '[', '', $markup_array_query_arg );
    227         $markup_array_query_args_stripped[] = str_replace( ']', '', $markup_array_query_arg_first_strip );
    228     }
     128function launch() {
     129    autoload_files();
    229130}
    230131
    231 /**
    232  * Function used to generate the toolbar second level links, using the args generated and passed to it.
    233  *
    234  * @param $toolbar_drop_down_links_arg      array   Array of the args required to generate each link.
    235  */
    236 function bvhg_toolbar_generate_second_level_links( $toolbar_drop_down_links_arg ) {
    237 
    238     global $wp_admin_bar;
    239 
    240     $wp_admin_bar->add_node(
    241         array(
    242             'id'       => $toolbar_drop_down_links_arg['id'],
    243             'parent'   => 'bvhg_html',
    244             'title'    => $toolbar_drop_down_links_arg['title'],
    245             'href'     => $toolbar_drop_down_links_arg['href'],
    246             'position' => 10,
    247         )
    248     );
    249 }
    250 
    251 add_action( 'wp_enqueue_scripts', 'bvhg_script_to_scrape_markup_on_page_Load', 1 );
    252 /**
    253  * Enqueue Script on page load that:
    254  * 1. Scrapes all data-markup-id values into an array.
    255  * 2. Adds all data-markup-id values as an additional class to their elements - to be used later to change css on the fly.
    256  * 3. Localizes script - sends values to be used by Ajax call used to receive the POSTed markup array.
    257  */
    258 function bvhg_script_to_scrape_markup_on_page_Load() {
    259 
    260     if ( is_customize_preview() ) {
    261         return;
    262     };
    263 
    264     wp_enqueue_script(
    265         'scrape-the-markup-ids',
    266         BVHG_BEANS_PLUGIN_URL . '/js/scrape_markup_ids.js',
    267         array( 'jquery' ),
    268         '1.0.0',
    269         true
    270     );
    271 
    272     wp_localize_script(
    273         'scrape-the-markup-ids',
    274         'myAjax',
    275         array(
    276             'ajaxurl' => admin_url( 'admin-ajax.php' ),
    277             'nonce'   => wp_create_nonce( 'my-special-string' )
    278         )
    279     );
    280 }
    281 
    282 add_action( 'wp_enqueue_scripts', 'bvhg_enqueue_css_if_guide_enabled', 1 );
    283 /**
    284  * Enqueue CSS only if BeansVisual Hook Guide is enabled
    285  */
    286 function bvhg_enqueue_css_if_guide_enabled() {
    287 
    288     if ( ! _beans_is_html_dev_mode() || is_customize_preview() ) {
    289         return;
    290     };
    291 
    292     if ( 'show' == isset( $_GET['bvhg_enable'] ) ) {
    293         wp_enqueue_style( 'bvhg_styles', BVHG_BEANS_PLUGIN_URL . '/css/bvhg_styles.css' );
    294     }
    295 }
    296 
    297 add_action( 'wp_ajax_bvhg_pass_markup_id_array', 'bvhg_pass_markup_id_array_callback' );
    298 /**
    299  * AJAX call back
    300  *
    301  * Receive Array containing all the data-markup-id attributes displayed by Beans Development Mode.
    302  * Check if transient exists, if so delete it, then save the received array as transient.
    303  *
    304  * Always die out of an AJAX call
    305  */
    306 function bvhg_pass_markup_id_array_callback() {
    307 
    308     check_ajax_referer( 'my-special-string', 'security' );
    309 
    310     if ( ! isset( $_POST['markup'] ) ) {
    311         return;
    312     }
    313 
    314     $non_sanitized_markup_array_from_ajax = $_POST['markup'];
    315     $non_sanitized_markup_array           = array_unique( $non_sanitized_markup_array_from_ajax );
    316 
    317     $sanitized_markup_array = array();
    318     foreach ( $non_sanitized_markup_array as $non_sanitized_markup ) {
    319         $sanitized_markup_array[] = sanitize_text_field( $non_sanitized_markup );
    320     }
    321 
    322     if ( get_transient( 'beans_html_markup_transient' ) ) {
    323         delete_transient( 'beans_html_markup_transient' );
    324     }
    325 
    326     set_transient( 'beans_html_markup_transient', $sanitized_markup_array, 12 * HOUR_IN_SECONDS );
    327 
    328     die();
    329 }
    330 
    331 
    332 add_action( 'beans_head', 'bvhg_beans_hooker' );
    333 /**
    334  * Hook in Beans Visual Hook Guide Functionality
    335  * 1. Execute function that adds action hooks and toolbar nodes for markup hooks that have been selected individually
    336  * 2. Check if show all hooks has been chosen, if so, enqueue css script with markup for chosen hooks only, then return.
    337  * 3. Execute function to add all action hooks for all possible markup
    338  * 4. Enqueue css for all possible markup hooks.
    339  */
    340 function bvhg_beans_hooker() {
    341 
    342     if (  ! _beans_is_html_dev_mode() || is_customize_preview() ) {
    343         return;
    344     }
    345 
    346     $markup_array = get_transient( 'beans_html_markup_transient' );
    347 
    348     if ( ! $markup_array || 'show' != isset( $_GET['bvhg_enable'] ) ) {
    349         return;
    350     }
    351 
    352     $escaped_markup_array = array();
    353     foreach ( $markup_array as $markup_string ) {
    354         $escaped_markup_array[] = esc_attr( $markup_string );
    355     }
    356 
    357     bvhg_add_action_hooks_toolbar_nodes_for_individual_markup_hooks( $escaped_markup_array );
    358 
    359     if ( 'show' != isset( $_GET['bvhg_enable_every_html_hook'] ) ) {
    360         bvhg_enqueue_css_script_with_markup_array_for_chosen_hooks_only();
    361 
    362         return;
    363     }
    364 
    365     bvhg_add_action_hooks_for_all_markup_hooks( $escaped_markup_array );
    366     bvhg_enqueue_css_script_with_markup_array_for_all_markup_hooks( $escaped_markup_array );
    367 
    368 }
    369 
    370 /**
    371  * Loop through the markup array and:
    372  * 1. Strip all square brackets so the array values can be used as query args.
    373  * 2. Execute function to add toolbar nodes for all possible markup hooks that can be chosen.
    374  * 3. Execute function that adds actions to display markup on all chosen action hooks.
    375  *
    376  * @param $markup_array     array   Array of all data-markup-id values scraped from the site and stored as transient.
    377  */
    378 function bvhg_add_action_hooks_toolbar_nodes_for_individual_markup_hooks( $markup_array ) {
    379 
    380     foreach ( $markup_array as $markup ) {
    381         $markup_stripped_of_opening_square_bracket = str_replace( '[', '', $markup );
    382         $markup_stripped_of_all_square_brackets    = str_replace( ']', '', $markup_stripped_of_opening_square_bracket );
    383         bvhg_add_toolbar_nodes_for_individual_markup_hooks( $markup, $markup_stripped_of_all_square_brackets );
    384         bvhg_add_action_hooks_for_individually_chosen_markup_hooks( $markup, $markup_stripped_of_all_square_brackets );
    385     }
    386 }
    387 
    388 
    389 /**
    390  * Function to add toolbar nodes for all possible markup hooks that can be chosen
    391  *
    392  * @param $markup                                       array   array of all data-markup-id values
    393  * @param $markup_stripped_of_square_brackets           array   array of all data-markup-id values stripped of square brackets
    394  *                                                      to be used as query args
    395  */
    396 function bvhg_add_toolbar_nodes_for_individual_markup_hooks( $markup, $markup_stripped_of_square_brackets ) {
    397 
    398     global $wp_admin_bar;
    399 
    400     $wp_admin_bar->add_node(
    401         array(
    402             'id'       => "bvhg_html_{$markup}hook",
    403             'parent'   => 'bvhg_html_list',
    404             'title'    => $markup,
    405             'href'     => esc_url( add_query_arg( "{$markup_stripped_of_square_brackets}", 'show' ) ),
    406             'position' => 10,
    407         )
    408     );
    409 }
    410 
    411 /**
    412  * Function that adds actions to display markup on all chosen action hooks
    413  * Add the current markup query arg to the global markup array for making individual css changes.
    414  *
    415  * @param $markup                                       array   array of all data-markup-id values
    416  * @param $markup_stripped_of_square_brackets           array   array of all data-markup-id values stripped of square brackets
    417  *                                                      to be used as query args
    418  *
    419  */
    420 function bvhg_add_action_hooks_for_individually_chosen_markup_hooks( $markup, $markup_stripped_of_square_brackets ) {
    421 
    422     global $markup_array_for_individual_css_changes;
    423 
    424     if ( 'show' == isset( $_GET[ $markup_stripped_of_square_brackets ] ) ) {
    425 
    426         $markup_array_for_individual_css_changes[] = $markup;
    427 
    428         add_action( "{$markup}_before_markup", function () use ( $markup ) {
    429             bvhg_beans_before_markup( $markup );
    430         }, 1 );
    431         add_action( "{$markup}_prepend_markup", function () use ( $markup ) {
    432             bvhg_beans_prepend_markup( $markup );
    433         }, 1 );
    434         add_action( "{$markup}_append_markup", function () use ( $markup ) {
    435             bvhg_beans_append_markup( $markup );
    436         }, 1 );
    437         add_action( "{$markup}_after_markup", function () use ( $markup ) {
    438             bvhg_beans_after_markup( $markup );
    439         }, 1 );
    440     }
    441 }
    442 
    443 /**
    444  * Function to enqueue css script with markup for chosen hooks only.
    445  */
    446 function bvhg_enqueue_css_script_with_markup_array_for_chosen_hooks_only() {
    447 
    448     global $markup_array_for_individual_css_changes;
    449 
    450     add_action( 'wp_enqueue_scripts', function () use ( $markup_array_for_individual_css_changes ) {
    451         bvhg_enqueue_element_id_script( $markup_array_for_individual_css_changes );
    452     }, 1, 999 );
    453 }
    454 
    455 /**
    456  * Function to add all action hooks for all possible markup
    457  *
    458  * @param $markup_array     array   Array of all data-markup-id values - used to add actions to all possible hooks.
    459  */
    460 function bvhg_add_action_hooks_for_all_markup_hooks( $markup_array ) {
    461 
    462     foreach ( $markup_array as $markup ) {
    463         add_action( "{$markup}_before_markup", function () use ( $markup ) {
    464             bvhg_beans_before_markup( $markup );
    465         }, 1 );
    466         add_action( "{$markup}_prepend_markup", function () use ( $markup ) {
    467             bvhg_beans_prepend_markup( $markup );
    468         }, 1 );
    469         add_action( "{$markup}_append_markup", function () use ( $markup ) {
    470             bvhg_beans_append_markup( $markup );
    471         }, 1 );
    472         add_action( "{$markup}_after_markup", function () use ( $markup ) {
    473             bvhg_beans_after_markup( $markup );
    474         }, 1 );
    475     }
    476 }
    477 
    478 /**
    479  * Function to add script to enqueue scripts hook, and provide array for localization.
    480  *
    481  * @param $markup_array     array   Array of all data-markup-id values - used to add actions to all possible hooks.
    482  */
    483 function bvhg_enqueue_css_script_with_markup_array_for_all_markup_hooks( $markup_array ) {
    484     add_action( 'wp_enqueue_scripts', function () use ( $markup_array ) {
    485         bvhg_enqueue_element_id_script( $markup_array );
    486     }, 1, 999 );
    487 }
    488 
    489 /**
    490  * Enqueue script to make css changes on fly
    491  *
    492  * 1. Add orange border around selected elements.
    493  * 2. Change wp_admin toolbar menu item to yellow for elements that are currently selected to be displayed.
    494  *
    495  * @param $markup_array     array   depending on query_arg displaying, will either be an array of just the chosen elements,
    496  *                          or every single element with a data-markup-id value.
    497  */
    498 function bvhg_enqueue_element_id_script( $markup_array ) {
    499 
    500     if ( ! $markup_array ) {
    501         return;
    502     }
    503 
    504     wp_enqueue_script(
    505         'element-id-css-changes',
    506         BVHG_BEANS_PLUGIN_URL . '/js/element_id_css.js',
    507         array( 'jquery' ),
    508         '1.0.0',
    509         true
    510     );
    511 
    512     wp_localize_script(
    513         'element-id-css-changes',
    514         'element',
    515         array( 'elementClass' => $markup_array )
    516     );
    517 }
    518 
    519 /**
    520  * Callback to be run on every possible $markup_before_markup html action hook
    521  *
    522  * Displays a div element containing the full dynamic action hook id
    523  *
    524  * @param   $markup string  data-markup-id attribute
    525  */
    526 function bvhg_beans_before_markup( $markup ) {
    527     echo '<div class="bvhg-hook-before-markup-cue" data-bvhg-hook-cue="' . $markup . '_before_markup">';
    528     echo $markup . '_before_markup</div>';
    529 }
    530 
    531 /**
    532  * Callback to be run on every possible $markup_prepend_markup html action hook
    533  *
    534  * Displays a div element containing the full dynamic action hook id
    535  *
    536  * @param   $markup string  data-markup-id attribute
    537  */
    538 function bvhg_beans_prepend_markup( $markup ) {
    539     echo '<div class="bvhg-hook-prepend-markup-cue" data-bvhg-hook-cue="' . $markup . '_prepend_markup">';
    540     echo $markup . '_prepend_markup</div>';
    541 }
    542 
    543 /**
    544  * Callback to be run on every possible $markup_append_markup html action hook
    545  *
    546  * Displays a div element containing the full dynamic action hook id
    547  *
    548  * @param   $markup string  data-markup-id attribute
    549  */
    550 function bvhg_beans_append_markup( $markup ) {
    551     echo '<div class="bvhg-hook-append-markup-cue" data-bvhg-hook-cue="' . $markup . '_append_markup">';
    552     echo $markup . '_append_markup</div>';
    553 }
    554 
    555 /**
    556  * Callback to be run on every possible $markup_after_markup html action hook
    557  *
    558  * Displays a div element containing the full dynamic action hook id
    559  *
    560  * @param   $markup string  data-markup-id attribute
    561  */
    562 function bvhg_beans_after_markup( $markup ) {
    563     echo '<div class="bvhg-hook-after-markup-cue" data-bvhg-hook-cue="' . $markup . '_after_markup">';
    564     echo $markup . '_after_markup</div>';
    565 }
    566 
    567 
    568 
    569 
    570 
    571 
     132launch();
  • beans-visual-hook-guide/trunk/readme.txt

    r1841179 r1858944  
    11=== Beans Visual Hook Guide ===
    2 Contributors: Deftly
     2Contributors: Deftly, hellofromtonya
    33Tags: Beans, Beans Framework, Beans HTML API, Development Tool, Hooks
    44Donate link: https://www.paypal.me/jeffcleverley
Note: See TracChangeset for help on using the changeset viewer.