function extra_customize_preview_enqueue_scripts() { $theme_version = SCRIPT_DEBUG ? time() : et_get_theme_version(); $suffix = SCRIPT_DEBUG ? '.js' : '.min.js'; wp_enqueue_script('extra-customizer', get_template_directory_uri() . '/scripts/theme-customizer' . $suffix, array('customize-preview'), $theme_version, true); $home_layout_id = extra_get_home_layout_id(); wp_localize_script('extra-customizer', 'EXTRA', array('ajaxurl' => set_url_scheme(admin_url('admin-ajax.php')), 'social_networks' => extra_get_social_networks(), 'settings' => extra_get_customizer_value_bound_settings(), 'current_home_layout_id' => $home_layout_id, 'extra_customizer_nonce' => wp_create_nonce('extra_customizer_nonce'))); }
function extra_admin_scripts($hook) { global $typenow; $template_dir = get_template_directory_uri(); $theme_version = SCRIPT_DEBUG ? time() : et_get_theme_version(); $protocol = is_ssl() ? 'https' : 'http'; $suffix = SCRIPT_DEBUG ? '.js' : '.min.js'; if ('nav-menus.php' == $hook) { wp_enqueue_script('extra_admin_nav_menu_js', $template_dir . '/includes/admin/scripts/nav-menu' . $suffix, array('jquery'), $theme_version, true); } if ('widgets.php' == $hook) { wp_enqueue_script('jquery-ui-accordion'); wp_enqueue_script('extra_widgets_js', $template_dir . '/includes/admin/scripts/widgets' . $suffix, array('jquery'), $theme_version, true); wp_enqueue_style('extra_widgets_css', $template_dir . '/includes/admin/styles/widgets.css', array(), $theme_version); wp_localize_script('extra_widgets_js', 'EXTRA', array('label_img_url' => __('Image Url:', 'extra'), 'label_link_url' => __('Link Url:', 'extra'), 'label_ad_html' => __('Ad HTML:', 'extra'), 'label_new_line' => __('Start on New Line', 'extra'), 'label_or' => __('OR', 'extra'), 'label_ad_number' => __('Ad #', 'extra'), 'authorize_nonce' => wp_create_nonce('authorize_nonce'), 'ajaxurl' => admin_url('admin-ajax.php', $protocol))); } if ('options-reading.php' == $hook) { $layouts_query = extra_get_layouts(array('posts_per_page' => -1, 'nopaging' => true, 'post_status' => 'publish')); if ($layouts_query->posts) { $layouts = array(); $home_layout_id = extra_get_home_layout_id(); foreach ($layouts_query->posts as $post) { $layouts[] = array("id" => $post->ID, "name" => $post->post_title); } wp_enqueue_script('extra_admin_options_reading_js', $template_dir . '/includes/admin/scripts/options-reading' . $suffix, array('jquery'), $theme_version, true); wp_localize_script('extra_admin_options_reading_js', 'EXTRA', array('layouts' => json_encode($layouts), 'current_home_layout_id' => $home_layout_id, 'show_on_front' => get_option('show_on_front'), 'extra_theme_layout_link' => sprintf(__('An <a href="%s">Extra Theme Layout</a> (select below)', 'extra'), 'edit.php?post_type=' . EXTRA_LAYOUT_POST_TYPE))); } wp_reset_postdata(); } if (in_array($hook, array('post.php', 'post-new.php'))) { // load every post and post edit page, i.e. posts, pages, CPTs wp_enqueue_script('extra_admin_gallery_images_js', $template_dir . '/includes/admin/scripts/gallery-images' . $suffix, array('jquery', 'jquery-ui-sortable'), $theme_version, true); if ('page' == $typenow) { wp_enqueue_script('extra_admin_page_template_js', $template_dir . '/includes/admin/scripts/page-template' . $suffix, array('jquery', 'jquery-effects-highlight'), $theme_version, true); } if ('post' == $typenow || EXTRA_PROJECT_POST_TYPE == $typenow) { wp_enqueue_script('extra_admin_posts_js', $template_dir . '/includes/admin/scripts/posts' . $suffix, array('jquery'), $theme_version, true); wp_localize_script('extra_admin_posts_js', 'EXTRA', array('label_breakdown_title' => __('Title:', 'extra'), 'label_breakdown_rating' => __('Rating (%):', 'extra'), 'label_breakdown_number' => __('Breakdown #', 'extra'))); } if ('post' == $typenow) { wp_enqueue_script('extra_admin_post_format_js', $template_dir . '/includes/admin/scripts/post-format' . $suffix, array('jquery', 'jquery-effects-highlight'), $theme_version, true); } if (EXTRA_LAYOUT_POST_TYPE == $typenow) { wp_enqueue_script('extra_admin_post_layout_js', $template_dir . '/includes/admin/scripts/post-layout' . $suffix, array('jquery'), $theme_version, true); wp_localize_script('extra_admin_post_layout_js', 'EXTRA', array('category_description' => __('Use this layout on the categories selected above.', 'extra'))); } // load *every* wp-admin post.php and post-new.php page wp_enqueue_script('extra_admin_js', $template_dir . '/includes/admin/scripts/admin-posts' . $suffix, array('jquery'), $theme_version, true); } }
function extra_layout_menu_home_layout_link() { if (is_admin()) { return; } $home_layout_id = extra_get_home_layout_id(); $default_layout_id = extra_get_default_layout_id(); if (!empty($home_layout_id)) { $pagehook = add_submenu_page('edit.php?post_type=' . EXTRA_LAYOUT_POST_TYPE, __('Edit Home Layout', 'extra'), __('Edit Home Layout', 'extra'), 'edit_pages', 'post.php?post=' . $home_layout_id . '&action=edit'); } if (!empty($default_layout_id)) { $pagehook = add_submenu_page('edit.php?post_type=' . EXTRA_LAYOUT_POST_TYPE, __('Edit Default Layout', 'extra'), __('Edit Default Layout', 'extra'), 'edit_pages', 'post.php?post=' . $default_layout_id . '&action=edit'); } }
function et_extra_show_home_layout() { return (bool) 'layout' == get_option('show_on_front') && extra_get_home_layout_id(); }
function et_pb_extra_add_default_layouts() { $et_builder_layouts = et_pb_extra_get_default_layouts(); $is_home_layout_exists = false; $is_index_layout_exists = false; $layout_args = array('posts_per_page' => -1, 'nopaging' => true, 'post_status' => 'publish', 'meta_key' => '_et_pb_predefined_default_layout', 'meta_value' => 'on'); $layout_args['meta_query'] = array(array('key' => '_et_pb_predefined_default_type', 'value' => 'home', 'compare' => 'IN')); // get the predefiend default home layouts $home_layouts_query = extra_get_layouts($layout_args); $layout_args['meta_query'] = array(array('key' => '_et_pb_predefined_default_type', 'value' => 'index', 'compare' => 'IN')); // get the predefiend default layouts $default_layouts_query = extra_get_layouts($layout_args); if ($home_layouts_query->posts) { $is_home_layout_exists = true; } if ($default_layouts_query->posts) { $is_index_layout_exists = true; } // do not proceed if both layouts already exist if ($is_index_layout_exists && $is_home_layout_exists) { return; } if (isset($et_builder_layouts) && is_array($et_builder_layouts)) { foreach ($et_builder_layouts as $et_builder_layout) { // do nothing if current layout already exist if (isset($et_builder_layout['default_home']) && $et_builder_layout['default_home'] && $is_home_layout_exists || isset($et_builder_layout['default_index']) && $et_builder_layout['default_index'] && $is_index_layout_exists) { continue; } $meta = array('_et_pb_predefined_default_layout' => 'on', '_et_pb_predefined_default_type' => $et_builder_layout['default_type']); // add meta for default home and index page layouts if ('home' === $et_builder_layout['default_type'] && false === extra_get_home_layout_id()) { $meta['_extra_layout_home'] = 1; } else { if ('index' === $et_builder_layout['default_type'] && false === extra_get_default_layout_id()) { $meta['_extra_layout_default'] = 1; } } et_pb_create_extra_layout($et_builder_layout['name'], $et_builder_layout['content'], $meta); } } }