Tagged: 

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1017922

    Hi,
    I am bulk adding pages using a self made plugin using WordPress’ Rest API. The generated pages have a custom post type.
    As the generated pages contain Avia short codes, they look well but are not yet “Enfold” pages. To make them Enfold pages, I have to open each page for editing, switch to the Advanced Layout Editor and press the Update button. Only then all Enfold settings are applied to the page.

    What do I have to do client/server side to turn generated pages into Enfold pages? I don’t mind if I have to run an update query on the database to achieve this.
    Regards,
    Maarten.

    #1018779

    Hey Maarten,

    Thank you for using Enfold.

    Set the builder status to “active”. There’s a public method for that.

    AviaBuilder::set_alb_builder_status('active', 3547 );
    

    3547 is the id of the post. It’s going to set the meta info “_aviaLayoutBuilder_active” of that particular post to “active”.

    Best regards,
    Ismael

    #1022693

    Dear Ismael,

    Thanks a lot for the provided answer but we are missing an important step (we think), namely how to ensure that the called function AviaBuilder::set_alb_builder_status is recognized? We tried several alternatives, like include, like use or like require, but none worked.

    Additional info: we plan to call this function in one of the php files of our plugin (in which namespaces are used and classes are referred by use statements and composer with autoload is also used.

    Thanks in advance.

    #1022799

    Hi,

    Thanks for the update. Plugins are loaded before the theme, so the function is not available yet. You can try to call the function inside the “init” or “after_setup_theme” hook. Check if the function or the AviaBuilder class exists.

    Best regards,
    Ismael

    #1031692

    Dear Ismael,

    Thanks a lot for your answer. I have tried out what you suggested but I am encountering some problems/challenges for what I can’t find the solution.

    This is what I have included in functions.php:

    “add_action(‘init’, ‘change_editor’);
    function change_editor()
    {
    $args = array(
    ‘post_type’ => ‘dzndoc’,
    ‘numberposts’ => -1,
    );
    $myposts = get_posts($args);
    if( $myposts ) {
    foreach ( $myposts as $mypost ) :
    AviaBuilder::set_alb_builder_status(‘active’, $mypost->ID);
    AviaBuilder::save_posts_alb_content($mypost->ID, $mypost->post_content);
    endforeach;
    wp_reset_postdata();
    }
    }”

    This activates the AdvancedLayoutBuilder for all my post, i.e. it creates and properly fills in the following meta_keys in wp_postmeta: _aviaLayoutBuilder_active and _aviaLayoutBuilderCleanData, but I am missing, as far as I can tell, at least the following two meta_keys: _avia_builder_shortcode_tree and _av_alb_posts_elements_state.

    My problem is that in editor mode I do not see the content elements which are defined in my page.

    See following example:

    For the following post:

    <div class=”flex_column av_one_fifth flex_column_div av-zero-column-padding first ” style=”border-radius: 0px;”>
    <div class=”av-special-heading av-special-heading-h1 ” style=”padding-bottom: 10px;”>
    <h1 class=”av-special-heading-tag “>Menu</h1>
    <div class=”special-heading-border”>
    <div class=”special-heading-inner-border”></div>
    </div>
    </div>
    <div class=”avia-builder-widget-area clearfix “>
    <div id=”dc_jqaccordion_widget-4” class=”widget clearfix “>
    <div id=”dc_jqaccordion_widget-4-item” class=”dcjq-accordion”></div>
    </div>
    </div>
    </div>
    <div class=”flex_column av_four_fifth flex_column_div av-zero-column-padding ” style=”border-radius: 0px;”>
    <div class=”av-special-heading av-special-heading-h1 ” style=”padding-bottom: 10px;”>
    <h1 class=”av-special-heading-tag “>Manipulate the Look of Diagrams</h1>
    <div class=”special-heading-border”>
    <div class=”special-heading-inner-border”></div>
    </div>
    </div>
    <section class=”av_textblock_section “>
    <div class=”avia_textblock “>
    <div class=”paragraph”>

    Many crossing lines in your system diagram or a very wild sequence diagram? Dezyne takes the order of the interface provides and requires declarations as the order in which objects are drawn left to right. So by changing the order of these declarations you can manipulate how the diagrams look like. E.g. compare pictures below (taken from the Camera example):

    </div>
    <div class=”paragraph”>

    <span class=”image”>image</span>

    </div>
    </div>
    </section></div>

    I have the following rows in wp_postmeta:
    205339 32801 _aviaLayoutBuilder_active active
    205340 32801 _aviaLayoutBuilderCleanData <div class=”flex_column av_one_fifth flex_column_div av-zero-column-padding first ” style=’border-radius:0px; ‘><p><div style=’padding-bottom:10px; ‘ class=’av-special-heading av-special-heading-h1 ‘><h1 class=’av-special-heading-tag ‘ itemprop=”headline” >Menu</h1><div class=’special-heading-border’><div class=’special-heading-inner-border’ ></div></div></div><br />
    <div class=’avia-builder-widget-area clearfix ‘><div id=”dc_jqaccordion_widget-4″ class=”widget clearfix “>
    <div class=”dcjq-accordion” id=”dc_jqaccordion_widget-4-item”>

    </div>
    </div></div></p></div>
    <div class=”flex_column av_four_fifth flex_column_div av-zero-column-padding ” style=’border-radius:0px; ‘><p><div style=’padding-bottom:10px; ‘ class=’av-special-heading av-special-heading-h1 ‘><h1 class=’av-special-heading-tag ‘ itemprop=”headline” >Manipulate the Look of Diagrams</h1><div class=’special-heading-border’><div class=’special-heading-inner-border’ ></div></div></div><br />
    <section class=”av_textblock_section ” itemscope=”itemscope” itemtype=”https://schema.org/CreativeWork” ><div class=’avia_textblock ‘ itemprop=”text” ><p>
    <div class=”paragraph”>
    <p>Many crossing lines in your system diagram or a very wild sequence diagram? Dezyne takes the order of the interface provides and requires declarations as the order in which objects are drawn left to right. So by changing the order of these declarations you can manipulate how the diagrams look like. E.g. compare pictures below (taken from the Camera example):</p>
    </div>
    <div class=”paragraph”>
    <p><span class=”image”>image</span></p>
    </div>

    </p>
    </div></section></p></div>

    210208 32801 _edit_lock 1541767986:46

    So my question boils down to: How do I get the rest of the needed meta_keys in wp_postmeta for my posts such that I will be able to edit content elements in the Advanced Layout Builder?

    Thanks in advance for your reaction.

    #1032812

    Hi,

    You can use this to create the element state:

    Avia_Builder()->element_manager()->get_elements_state( 'post', $mypost->ID );
    

    And build the shortcode tree.

    
    ShortcodeHelper::clean_up_shortcode( $_POST['_aviaLayoutBuilderCleanData'], 'content' );
    

    Final code may look like this:

    
     foreach ( $myposts as $mypost ) :
        $content = $mypost->post_content;
         $tree = ShortcodeHelper::build_shortcode_tree( $content );
        AviaBuilder::set_alb_builder_status( 'active', $mypost->ID );
        AviaBuilder::save_posts_alb_content( $mypost->ID, $content );
        Avia_Builder()->element_manager()->get_elements_state( 'post', $mypost->ID );
        ShortcodeHelper::clean_up_shortcode( $_POST['_aviaLayoutBuilderCleanData'], 'content' );
        update_post_meta( $mypost->ID, '_avia_builder_shortcode_tree', $tree );
    endforeach;
    

    Best regards,
    Ismael

    #1033031

    Thanks a lot.

    With a little change in ‘template’ page retrieval method and with the changes you suggested we managed to go one step further towards the final goal.

    #1033435

    Hi,

    You’re welcome. Please feel free to open a new thread if you need anything else.

    Have a nice day. :)

    Best regards,
    Ismael

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Adding pages using the WordPress Rest Api’ is closed to new replies.