ID, '_bgbn-sections', true ); $bgbn_sections = ( is_array( $bgbn_sections ) ) ? $bgbn_sections : array(); // Load the boilerplate templates get_template_part( 'inc/builder/core/templates/menu' ); get_template_part( 'inc/builder/core/templates/stage', 'header' ); $section_data = $this->get_section_data( $post_local->ID ); $registered_sections = bgbn_get_sections(); // Print the current sections foreach ( $section_data as $section ) { if ( isset( $registered_sections[ $section['section-type'] ]['display_template'] ) ) { // Print the saved section $this->load_section( $registered_sections[ $section['section-type'] ], $section ); } } get_template_part( 'inc/builder/core/templates/stage', 'footer' ); // Add the sort input $section_order = get_post_meta( $post_local->ID, '_bgbn-section-ids', true ); $section_order = ( ! empty( $section_order ) ) ? implode( ',', $section_order ) : ''; echo ''; } /** * Enqueue the JS and CSS for the admin. * * @since 1.0.0. * * @param string $hook_suffix The suffix for the screen. * @return void */ public function admin_enqueue_scripts( $hook_suffix ) { // Only load resources if they are needed on the current page if ( ! in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) || 'page' !== get_post_type() ) { return; } // Enqueue the CSS wp_enqueue_style( 'bgbn-builder', get_template_directory_uri() . '/inc/builder/core/css/builder.css', array(), bgbn_VERSION ); wp_enqueue_style( 'wp-color-picker' ); // Dependencies regardless of min/full scripts $dependencies = array( 'wplink', 'utils', 'wp-color-picker', 'jquery-effects-core', 'jquery-ui-sortable', 'backbone', ); // Only load full scripts for WordPress.com and those with SCRIPT_DEBUG set to true wp_register_script( 'bgbn-builder/js/tinymce.js', get_template_directory_uri() . '/inc/builder/core/js/tinymce.js', array(), bgbn_VERSION, true ); wp_register_script( 'bgbn-builder/js/models/section.js', get_template_directory_uri() . '/inc/builder/core/js/models/section.js', array(), bgbn_VERSION, true ); wp_register_script( 'bgbn-builder/js/collections/sections.js', get_template_directory_uri() . '/inc/builder/core/js/collections/sections.js', array(), bgbn_VERSION, true ); wp_register_script( 'bgbn-builder/js/views/menu.js', get_template_directory_uri() . '/inc/builder/core/js/views/menu.js', array(), bgbn_VERSION, true ); wp_register_script( 'bgbn-builder/js/views/section.js', get_template_directory_uri() . '/inc/builder/core/js/views/section.js', array(), bgbn_VERSION, true ); wp_enqueue_script( 'bgbn-builder', get_template_directory_uri() . '/inc/builder/core/js/app.js', apply_filters( 'bgbn_builder_js_dependencies', array_merge( $dependencies, array( 'bgbn-builder/js/tinymce.js', 'bgbn-builder/js/models/section.js', 'bgbn-builder/js/collections/sections.js', 'bgbn-builder/js/views/menu.js', 'bgbn-builder/js/views/section.js', ) ) ), bgbn_VERSION, true ); // Add data needed for the JS $data = array( 'pageID' => get_the_ID(), ); wp_localize_script( 'bgbn-builder', 'bgbnBuilderData', $data ); } /** * Print additional, dynamic CSS for the builder interface. * * @since 1.0.0. * * @return void */ public function admin_print_styles() { global $pagenow; // Do not complete the function if the product template is in use (i.e., the builder needs to be shown) if ( 'page' !== get_post_type() ) { return; } ?>
$data, 'section' => $section, ); // Include the template bgbn_load_section_template( $section['builder_template'], $section['path'] ); // Destroy the variable as a good citizen does unset( $GLOBALS['bgbn_section_data'] ); } /** * Print out the JS section templates * * @since 1.0.0. * * @return void */ public function print_templates() { global $hook_suffix, $typenow, $bgbn_is_js_template; $bgbn_is_js_template = true; // Only show when adding/editing pages if ( 'page' !== $typenow || ! in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) )) { return; } // Print the templates foreach ( bgbn_get_sections() as $key => $section ) : ?> array( 'toolbar1' => 'bold,italic,link,unlink', 'toolbar2' => '', 'toolbar3' => '', 'toolbar4' => '', ), 'quicktags' => array( 'buttons' => 'strong,em,link', ), 'editor_height' => 150, ) ); // Remove the default media buttons action and replace it with the custom one remove_action( 'media_buttons', 'media_buttons' ); add_action( 'media_buttons', array( $this, 'media_buttons' ) ); // Render the editor wp_editor( $content, $name, $settings ); // Reinstate the original media buttons function remove_action( 'media_buttons', array( $this, 'media_buttons' ) ); add_action( 'media_buttons', 'media_buttons' ); } /** * Add the media buttons to the text editor. * * This is a copy and modification of the core "media_buttons" function. In order to bgbn the media editor work * better for smaller width screens, we need to wrap the button text in a span tag. By doing so, we can hide the * text in some situations. * * @since 1.0.0. * * @param string $editor_id The value of the current editor ID. * @return void */ public function media_buttons( $editor_id = 'content' ) { $post = get_post(); if ( ! $post && ! empty( $GLOBALS['post_ID'] ) ) { $post = $GLOBALS['post_ID']; } wp_enqueue_media( array( 'post' => $post ) ); $img = ''; // Note that the theme textdomain is not used for Add Media in order to use the core l10n echo '' . $img . ' '; } /** * Append the editor styles to the section editors. * * Unfortunately, the `wp_editor()` function does not support a "content_css" argument. As a result, the stylesheet * for the "content_css" parameter needs to be added via a filter. * * @since 1.0.0. * * @param array $mce_init The array of tinyMCE settings. * @param string $editor_id The ID for the current editor. * @return array The modified settings. */ function tiny_mce_before_init( $mce_init, $editor_id ) { // Only add stylesheet to a section editor if ( false === strpos( $editor_id, 'bgbn' ) ) { return $mce_init; } // Editor styles $editor_styles = array(); if ( '' !== $google_request = bgbn_get_google_font_uri() ) { $editor_styles[] = $google_request; } $editor_styles[] = get_template_directory_uri() . '/css/font-awesome.css'; $editor_styles[] = get_template_directory_uri() . '/css/editor-style.css'; // Append in the customizer styles if available if ( function_exists( 'bgbn_get_css' ) && bgbn_get_css()->build() ) { $editor_styles[] = add_query_arg( 'action', 'bgbn-css', admin_url( 'admin-ajax.php' ) ); } // Create string of CSS files $content_css = implode( ',', $editor_styles ); // If there is already a stylesheet being added, append and do not override if ( isset( $mce_init['content_css'] ) ) { $mce_init['content_css'] .= ',' . $content_css; } else { $mce_init['content_css'] = $content_css; } return $mce_init; } /** * Denote the default editor for the user. * * Note that it would usually be ideal to expose this via a JS variable using wp_localize_script; however, it is * being printed here in order to guarantee that nothing changes this value before it would otherwise be printed. * The "after_wp_tiny_mce" action appears to be the most reliable place to print this variable. * * @since 1.0.0. * * @param array $settings TinyMCE settings. * @return void */ public function after_wp_tiny_mce( $settings ) { ?> $value ) { // Only consider builder values if ( 0 === strpos( $key, '_bgbn:' ) ) { // Get the individual pieces $temp_data[ str_replace( '_bgbn:', '', $key ) ] = $value[0]; } } } // Create multidimensional array from postmeta $data = $this->create_array_from_meta_keys( $temp_data ); // Reorder the data in the order specified by the section IDs if ( is_array( $ids ) ) { foreach ( $ids as $id ) { if ( isset( $data[ $id ] ) ) { $ordered_data[ $id ] = $data[ $id ]; } } } return $ordered_data; } /** * Convert an array with array keys that map to a multidimensional array to the array. * * @since 1.0.0. * * @param array $arr The array to convert. * @return array The converted array. */ function create_array_from_meta_keys( $arr ) { // The new multidimensional array we will return $result = array(); // Process each item of the input array foreach ( $arr as $key => $value ) { // Store a reference to the root of the array $current = & $result; // Split up the current item's key into its pieces $pieces = explode( ':', $key ); /** * For all but the last piece of the key, create a new sub-array (if necessary), and update the $current * variable to a reference of that sub-array. */ for ( $i = 0; $i < count( $pieces ) - 1; $i++ ) { $step = $pieces[ $i ]; if ( ! isset( $current[ $step ] ) ) { $current[ $step ] = array(); } $current = & $current[ $step ]; } // Add the current value into the final nested sub-array $current[ $pieces[ $i ] ] = $value; } // Return the result array return $result; } /** * Display information about duplicating posts. * * @since 1.1.0. * * @return void */ public function post_submitbox_misc_actions() { ?>%2$s', esc_url( bgbn_get_plus_link( 'duplicator' ) ), 'Bigbusiness Plus' ) ); ?>