+ Reply to Thread
Results 1 to 7 of 7

Thread: Sharing data using hook boxes

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    18

    Question Sharing data using hook boxes

    I have two separate WordPress Catalyst sites sharing a common database. Each site has its own set of tables in the same database.

    I would like to create a Custom Hook Box in site 1, save it as a shortcode then embed that shortcode from site 1 into site 2. I'm guessing that i have to use PHP coding to change the prefix for the database of site 1 to pull the data into site 2.

    Can i do this?
    Where would i put the PHP code?
    What table is the short code stored in (I created a simple custom hook box and i don't see the data in the wp_catalyst_hooks table.

    Thanks,
    Steve

  2. #2
    Catalyst Developer eric's Avatar
    Join Date
    Dec 2010
    Posts
    6,328
    Hey Steve,

    I'm currently having trouble wrapping my brain around your question at the moment but to answer your last question, the Custom Hook Boxes are stored in two DB instances, both inside the wp_options table. One is called catalyst_custom_hook_boxes and the other is catalyst_custom_hook_box_content. The second one holds all the data you add to the Hook Box textarea and the first holds all the other data.

    Eric

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    18
    Hi Eric,
    Sorry for the poor explanation. I also am having trouble wrapping my head around it too and i'm developing it

    There is a single MySQL database that has multiple sets of tables, a set of tables for each slave and a set of tables for the master. Each slave and master has its own database prefix, for example site1_catalyst_hooks, site2_catalyst_hooks, etc.

    Each slave has its own Catalyst theme installed so the front ends can look totally different.

    The reason i am asking about shortcodes is that i can create one custom hook box (shortcode) for example, [product1_content] in my master database tables.

    Then in each slave site the Catalyst Page for Product 1 in the content field would say [catalyst_hook_box name="product1_content"].

    Then if i want to change the information in [product1_content] i change it only once in the master database tables and the slave sites don't have to change because they reference the shortcode by the Catalyst nomenclature.

    I'm not sure if i made the explanation better or worse but thank you for taking the time to answer!

    Thank you,
    Steve

  4. #4
    Catalyst Developer eric's Avatar
    Join Date
    Dec 2010
    Posts
    6,328
    Hey Steve,

    I'm not sure if that would work or not. Here is the code for the Custom Hook Box Shortcodes:

    PHP Code:
    // Allow Custom Hook Boxes to be turned into shortcodes.
    add_shortcode'catalyst_hook_box''catalyst_hook_box_shortcode' );
    // Enable shortcodes in Custom Hook Boxe textareas.
    add_filter'catalyst_hook_box_shortcode''do_shortcode' );
    /**
     * Determine which Custom Hook Boxes are set to become shortcodes, if any,
     * and then return their textarea content.
     *
     * @since 1.0
     * @return Custom Hook Box textarea content.
     */
    function catalyst_hook_box_shortcode$atts )
    {
        
    extractshortcode_atts( array(
        
    "name" => '',
        ), 
    $atts ) );
        
        
    $catalyst_hooks get_option'catalyst_custom_hook_boxes' );
        
    $catalyst_hook_content get_option'catalyst_custom_hook_box_content' );
        
    $text '';
        
        foreach( 
    $catalyst_hooks as $key => $value )
        {
            if( 
    $catalyst_hooks[$key]['hook_name'] == $name && ( $catalyst_hooks[$key]['is_active'] == 'hkd' || $catalyst_hooks[$key]['is_active'] == 'no' ) )
                return;
                
            
    $text apply_filters'catalyst_hook_box_shortcode'htmlspecialchars_decodestripslashes$catalyst_hook_content[$name] ) ) );
        }
        
        
    // Allow PHP code to execute in Custom Hook Boxes.
        
    ob_start();
        eval( 
    '?>'.$text);
        
    $text ob_get_contents();
        
    ob_end_clean();
        
        return 
    $text;

    Note that it's this code that pulls in the Hook Box settings from the DB:

    PHP Code:
        $catalyst_hooks get_option'catalyst_custom_hook_boxes' );
        
    $catalyst_hook_content get_option'catalyst_custom_hook_box_content' ); 
    I don't have a silver bullet answer for you at the moment, but that's at least some insight into the inter-workings of this functionality.

    Eric

  5. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    18
    Eric,

    Thank you so much! I'm going to try this. I'm so new to PHP it may take me a while but at least i have a good start thanks to you!

    Catalyst rocks!

    Thanks,

  6. #6
    Junior Member
    Join Date
    Jun 2012
    Posts
    18
    Hey Eric,

    FYI - I found a simpler way to implement this using the Include Content Slice plug-in.

    Maybe this will be of some help to others.

    Thanks again,
    Steve

  7. #7
    Catalyst Developer eric's Avatar
    Join Date
    Dec 2010
    Posts
    6,328
    Hey Steve,

    Thanks for sharing that info and glad you found an effective solution.

    Eric

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts