function load_admin_scripts($hook)
 {
     global $version, $pagenow, $current_screen;
     if (in_array($hook, array('post-new.php', 'post.php')) && in_array(get_post_type(), themify_post_types())) {
         wp_enqueue_script('themify-builder-plugin-compat', THEMIFY_BUILDER_URI . '/js/themify.builder.plugin.compat.js', array('jquery'), $version, true);
         wp_localize_script('themify-builder-plugin-compat', 'TBuilderPluginCompat', apply_filters('themify_builder_plugin_compat_vars', array('wpseo_active' => $this->is_plugin_active('wordpress-seo/wp-seo.php'), 'wpseo_builder_content_text' => __('Themify Builder: ', 'themify'))));
     }
 }
/**
 * Remove WordPress' Post Thumbnail metabox. This functionality is handled by Themify
 * @since 1.1.5
 */
function themify_cpt_image_box()
{
    $types = themify_post_types();
    foreach ($types as $type) {
        remove_meta_box('postimagediv', $type, 'side');
    }
}
Example #3
0
/**
 * Enqueue JS and CSS for Themify settings page and meta boxes
 * @param String $page
 * @since 1.1.1
 *******************************************************/
function themify_enqueue_scripts($page)
{
    $pagenow = isset($_GET['page']) ? $_GET['page'] : '';
    // Don't do anything while updating the theme
    if ('themify' == $pagenow && isset($_GET['action']) && 'upgrade' == $_GET['action']) {
        return;
    }
    global $typenow;
    $types = themify_post_types();
    $pages = apply_filters('themify_top_pages', array('post.php', 'post-new.php', 'toplevel_page_themify', 'nav-menus.php'));
    $pagenows = apply_filters('themify_pagenow', array('themify'));
    wp_register_script('meta-box-tabs', THEMIFY_URI . '/js/meta-box-tabs.js', array('jquery'), '1.0', true);
    wp_register_script('media-library-browse', THEMIFY_URI . '/js/media-lib-browse.js', array('jquery'), '1.0', true);
    wp_register_style('themify-ui', THEMIFY_URI . '/css/themify-ui.css', array(), THEMIFY_VERSION);
    wp_register_style('themify-ui-rtl', THEMIFY_URI . '/css/themify-ui-rtl.css', array(), THEMIFY_VERSION);
    wp_register_style('colorpicker', THEMIFY_URI . '/css/jquery.minicolors.css', array(), THEMIFY_VERSION);
    wp_register_script('validate', THEMIFY_URI . '/js/jquery.validate.pack.js', array('jquery'), THEMIFY_VERSION);
    wp_register_script('colorpicker-js', THEMIFY_URI . '/js/jquery.minicolors.js', array('jquery'), THEMIFY_VERSION);
    wp_register_script('themify-scripts', THEMIFY_URI . '/js/scripts.js', array('jquery'), THEMIFY_VERSION);
    wp_register_script('themify-plupload', THEMIFY_URI . '/js/plupload.js', array('jquery', 'themify-scripts'), THEMIFY_VERSION);
    wp_register_script('gallery-shortcode', THEMIFY_URI . '/js/gallery-shortcode.js', array('jquery', 'themify-scripts'), THEMIFY_VERSION, true);
    wp_register_style('magnific', THEMIFY_URI . '/css/lightbox.css', array(), THEMIFY_VERSION);
    wp_register_script('magnific', THEMIFY_URI . '/js/lightbox.js', array('jquery'), THEMIFY_VERSION, true);
    // Custom Write Panel
    if (($page == 'post.php' || $page == 'post-new.php') && in_array($typenow, $types)) {
        wp_enqueue_script('meta-box-tabs');
        wp_enqueue_script('media-library-browse');
    }
    // Register icon assets for later enqueueing.
    wp_register_style('themify-font-icons-css', THEMIFY_URI . '/fontawesome/css/font-awesome.min.css', array(), THEMIFY_VERSION);
    wp_register_script('themify-font-icons-js', THEMIFY_URI . '/js/themify.font-icons-select.js', array('jquery'));
    wp_localize_script('themify-font-icons-js', 'themifyIconPicker', array('icons_list' => THEMIFY_URI . '/fontawesome/list.html'));
    wp_register_style('themify-icons', THEMIFY_URI . '/themify-icons/themify-icons.css', array(), THEMIFY_VERSION);
    wp_register_style('google-fonts-admin', themify_https_esc('http://fonts.googleapis.com/css') . '?family=Open+Sans:400,300,600|Montserrat');
    // Settings Panel
    if ($page == 'toplevel_page_themify') {
        wp_enqueue_script('jquery-ui-sortable');
    }
    if (in_array($page, $pages)) {
        //Enqueue styles
        wp_enqueue_style('themify-ui');
        if (is_rtl()) {
            wp_enqueue_style('themify-ui-rtl');
        }
        wp_enqueue_style('colorpicker');
        //Enqueue scripts
        wp_enqueue_script('jquery');
        wp_enqueue_script('jquery-ui-core');
        wp_enqueue_script('jquery-ui-tabs');
        wp_enqueue_script('json2');
        wp_enqueue_script('plupload-all');
        wp_enqueue_script('validate');
        wp_enqueue_script('colorpicker-js');
        if (in_array($typenow, $types) || in_array($pagenow, $pagenows)) {
            //Don't include Themify JavaScript if we're not in one of the Themify-managed pages
            wp_enqueue_script('themify-scripts');
            wp_enqueue_script('themify-plupload');
        }
        // Enqueue font icon assets.
        themify_font_icons_admin_assets();
        wp_enqueue_style('magnific');
        wp_enqueue_script('magnific');
    }
    //Inject variable values to scripts.js previously enqueued
    wp_localize_script('themify-scripts', 'themify_js_vars', array('themify' => THEMIFY_URI, 'nonce' => wp_create_nonce('ajax-nonce'), 'admin_url' => admin_url('admin.php?page=themify'), 'ajax_url' => admin_url('admin-ajax.php'), 'app_url' => get_template_directory_uri() . '/themify/', 'theme_url' => get_template_directory_uri() . '/', 'blog_url' => site_url() . '/'));
    // Inject variable for Plupload
    $global_plupload_init = array('runtimes' => 'html5,flash,silverlight,html4', 'browse_button' => 'plupload-browse-button', 'container' => 'plupload-upload-ui', 'drop_element' => 'drag-drop-area', 'file_data_name' => 'async-upload', 'multiple_queues' => true, 'max_file_size' => wp_max_upload_size() . 'b', 'url' => admin_url('admin-ajax.php'), 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), 'filters' => array(array('title' => __('Allowed Files', 'themify'), 'extensions' => 'jpg,jpeg,gif,png,ico,zip,txt,svg')), 'multipart' => true, 'urlstream_upload' => true, 'multi_selection' => false, 'multipart_params' => array('_ajax_nonce' => '', 'action' => 'themify_plupload', 'imgid' => 0));
    wp_localize_script('themify-scripts', 'global_plupload_init', $global_plupload_init);
    wp_localize_script('themify-scripts', 'themify_lang', array('confirm_reset_styling' => __('Are you sure you want to reset your theme style?', 'themify'), 'confirm_reset_settings' => __('Are you sure you want to reset your theme settings?', 'themify'), 'confirm_refresh_webfonts' => __('Are you sure you want to refresh the Google Fonts list? This will also save the current settings.', 'themify'), 'check_backup' => __('Make sure to backup before upgrading. Files and settings may get lost or changed.', 'themify'), 'confirm_delete_image' => __('Do you want to delete this image permanently?', 'themify'), 'invalid_login' => __('Invalid username or password.<br/>Contact <a href="http://themify.me/contact">Themify</a> for login issues.', 'themify'), 'unsuscribed' => __('Your membership might be expired. Login to <a href="http://themify.me/member">Themify</a> to check.', 'themify'), 'enable_zip_upload' => sprintf(__('Go to your <a href="%s">Network Settings</a> to enable <strong>zip</strong>, <strong>txt</strong> and <strong>svg</strong> extensions in <strong>Upload file types</strong> field.', 'themify'), esc_url(network_admin_url('settings.php') . '#upload_filetypes')), 'filesize_error' => __('The file you are trying to upload exceeds the maximum file size allowed.', 'themify'), 'filesize_error_fix' => sprintf(__('Go to your <a href="%s">Network Settings</a> and increase the value of the <strong>Max upload file size</strong>.', 'themify'), esc_url(network_admin_url('settings.php') . '#fileupload_maxk')), 'confirm_demo' => __('This will import demo and override current Themify panel settings.', 'themify'), 'confirm_clear_builder_cache' => esc_html__('This will clear all builder caches. click ok to continue.', 'themify')));
}
 /**
  * Add custom Themify Builder button after Add Media btn
  * @param string $context 
  * @return string
  */
 function add_custom_switch_btn($context)
 {
     global $pagenow;
     $post_types = themify_post_types();
     if ('post.php' == $pagenow && in_array(get_post_type(), $post_types)) {
         $context .= sprintf('<a href="#" class="button themify_builder_switch_btn">%s</a>', __('Themify Builder', 'themify'));
     }
     return $context;
 }
    /**
     * Part of conversion from legacy feature image to post thumbnail.
     * Collect all posts that must and CAN be fixed.
     * @since 1.1.3
     */
    function ajax_collectposts()
    {
        //Get all CPT created by Themify
        $posttypes = themify_post_types();
        //Get list of posts that have a path in feature_image
        $themify_postlist = get_posts(array('numberposts' => -1, 'post_type' => $posttypes, 'meta_query' => array('relation' => 'OR', array('key' => 'post_image'), array('key' => 'feature_image'))));
        $html = '<style type="text/css">
		.posttofix{
			display: none;
			height: 500px;
			overflow: scroll;
			overflow-x: hidden;
			overflow-y: scroll;
			border: 1px solid #EEE;
			padding: 0 20px 0 10px;
			background: #F6F6F6;
			font-size: 11px;
			line-height: 120%;
		}
		.posttofix ol li{
			margin-bottom:20px;
		}
		.posttofix ol p{
			margin-top: -0.5em;
		}
		.posttofix ol h3 small{
			font-weight:normal;
			clear:both;
			display: block;
			margin-top: .5em;
		}
		</style>';
        //Start displaying errors
        $html .= '<h3>' . __('Post Image Migrator', 'themify') . '</h3>';
        $html .= '<p>' . __("Use this tool to convert the Themify Post Image and Feature Image custom field to WordPress Featured Image. If the image URL is not in the same domain than your WordPress site, the processor will skip it.", 'themify') . '</p><p><a href="#" id="processposts" class="button hide-if-no-js" title="' . __('Process all posts that can be migrated.', 'themify') . '">' . __('Process All Posts', 'themify') . '</a> &nbsp; <a href="#" id="showdetails">' . __('See Details', 'themify') . '</a></p>';
        $html .= '<div class="posttofix">';
        $html .= '<p id="fix-types">' . __('Filter view by:', 'themify') . ' ';
        $html .= '<a href="#" id="fix-all" style="margin-right: 10px;">' . __('All', 'themify') . '</a>';
        $fixtypes = array('post', 'slider', 'highlights', 'menu');
        foreach ($fixtypes as $type) {
            if (post_type_exists($type)) {
                $html .= '<a href="#" id="fix-' . $type . '" style="margin-right: 10px;">' . ucwords($type) . '</a>';
            }
        }
        $html .= '</p>';
        $html .= '<ol>';
        //Initialize list of posts to be fixed
        $themify_postfix = array();
        foreach ($themify_postlist as $post) {
            //Get wp post thumbnail
            $thumbnailid = get_post_meta($post->ID, '_thumbnail_id', true);
            //Get themify legacy Post Image. We give priority to this field.
            $featimg = get_post_meta($post->ID, 'post_image', true);
            //If there was no URL here, we will try another field
            if (empty($featimg)) {
                //Get themify legacy Feature Image. If the Post Image field is empty, try this one.
                $featimg = get_post_meta($post->ID, 'feature_image', true);
            }
            //Parse URL of legacy feature image to obtain the host later
            $featimgurl = parse_url($featimg);
            //Save ID, post type, title and a link to edit the post
            $postedit = '<li class="fix-all fix-' . $post->post_type . '">
				<h3>' . $post->post_title . '
						<small>ID: ' . $post->ID . ' | Type: ' . ucwords($post->post_type) . ' | <a href="' . get_edit_post_link($post->ID) . '">Edit post</a>
						</small>
				</h3>';
            if ($thumbnailid) {
                $thumbpost = get_post($thumbnailid);
                if ($featimg == $thumbpost->guid) {
                    //$html .=  $postedit . '<p><strong style="color:#060;">' . __("Featured Image and Themify's Post Image match!", 'themify') . '</strong></p>';
                } else {
                    //Display details and edit link for this post
                    $html .= $postedit;
                    ///Parse URL of wp post thumbnail to obtain the host later
                    $thumburl = parse_url($thumbpost->guid);
                    //Display the hosts of the wp post thumbnail and legacy feature image
                    $html .= '<p><strong>' . __('Featured Image:', 'themify') . '</strong><br/>' . $thumbpost->guid . '</p>';
                    $html .= '<p><strong>' . __("Themify's Post Image:", 'themify') . '</strong><br/>' . $featimg . '</p>';
                    if ($featimgurl['host'] == $thumburl['host']) {
                        //Image is in the same server, so we can add it.
                        $html .= '<p style="color:#480;">' . __("The post image URL appears to be in the same server that this WordPress installation so it will be set as the Featured Image.", 'themify') . '</p>';
                        //Add post to list of posts to be fixed
                        $themify_postfix[] = $post;
                    } else {
                        //Legacy image is not in the same server so it can't be added as the post thumbnail
                        $html .= '<p style="color:#d00;">' . __("The post image URL is not in the same server than your WordPress installation so it can't be set as the Featured Image.", 'themify') . '</p>';
                    }
                }
            } else {
                // Initialize WP Filesystem API
                require_once ABSPATH . 'wp-admin/includes/file.php';
                $url = wp_nonce_url('admin.php?page=regenerate-thumbnails', 'themify-regen_thumbs');
                if (false === ($creds = request_filesystem_credentials($url, '', true, false, null))) {
                    return true;
                }
                if (!WP_Filesystem($creds)) {
                    request_filesystem_credentials($url, '', true, false, null);
                    return true;
                }
                global $wp_filesystem, $blog_id;
                //get site or blog upload dir
                $updir = wp_upload_dir();
                //since WPMS redirects the upload dir, we need to build the path to the image in the server
                if (is_multisite()) {
                    //if $blog_id has been correctly instanced and it's a blog
                    if (isset($blog_id) && $blog_id > 0) {
                        //split image url in two and remove /files string
                        $imgexp = explode('/files', $featimg);
                        //if we have the last portion with the directories path ordered by date
                        if (isset($imgexp[1])) {
                            //get server path to the image
                            $serverimgpath = $updir['basedir'] . $imgexp[1];
                        } else {
                            $html .= '<p style="color:#d00;">' . __('Image not found. The path to the image is broken.', 'themify') . '<br/><small>' . $featimg . '</small></p>';
                        }
                    } else {
                        $html .= '<p style="color:#d00;">' . __('Multisite reference OK but bad blog ID.', 'themify') . '<br/><small>' . $featimg . '</small></p>';
                    }
                } else {
                    //split image url in two and remove /files string
                    $imgexp = explode('/uploads', $featimg);
                    $serverimgpath = $updir['basedir'] . $imgexp[1];
                }
                //Display details and edit link for this post
                $html .= $postedit;
                //get home url to check later
                $homeurl = home_url();
                ///Parse home URL to obtain the host later
                $localurl = parse_url($homeurl);
                //same domain or host
                if ($featimgurl['host'] == $localurl['host']) {
                    //check if file exists
                    if ($wp_filesystem->exists($serverimgpath)) {
                        if (is_multisite()) {
                            //multisite install, same domain
                            $featimginfo = pathinfo($featimg);
                            $featimgpath = $featimginfo['dirname'];
                            $featimgpath = split('files', $featimgpath);
                            if (home_url() . '/' == $featimgpath[0]) {
                                $html .= '<p style="color:#480;">' . __('No featured image set but the post image can be set as the featured image.', 'themify') . '<br/><small>' . $featimg . '</small></p>';
                                $themify_postfix[] = $post;
                            } else {
                                $html .= '<p style="color:#d00;">' . __('No Featured Image set and the post image is in a different site from your multisite installation.', 'themify') . '<br/><small>' . $featimg . '</small></p>';
                            }
                        } else {
                            //is single wordpress
                            $existe = $wp_filesystem->is_file($serverimgpath);
                            $fiinfo = pathinfo($featimg);
                            $fipath = $fiinfo['dirname'];
                            $fipath = split('/wp-content/uploads', $fipath);
                            /*ob_start();
                            		dumpit($serverimgpath);
                            		dumpit($existe);
                            		dumpit($fipath);
                            		dumpit($homeurl);
                            		//$html .= ob_get_contents();
                            		ob_end_clean();*/
                            if ($homeurl != $fipath[0]) {
                                //single wordpress, same domain or host, different subdirectory
                                $html .= '<p style="color:#d00;">' . __('The URL for the post image is in a different subdirectory from your host.', 'themify') . '<br/><small>' . $featimg . '</small></p>';
                            } else {
                                $html .= '<p style="color:#480;">' . __('No Featured Image set but the post image can be set as the featured image.', 'themify') . '<br/><small>' . $featimg . '</small></p>';
                                $themify_postfix[] = $post;
                            }
                        }
                    } else {
                        $html .= '<p style="color:#d00;">' . __('The referenced post image does not exist.', 'themify') . '<br/><small>' . $featimg . '</small></p>';
                    }
                } else {
                    $html .= '<p style="color:#d00;">' . __('The post image is not in the same server than your WordPress installation so it can\'t be set as the featured image.', 'themify') . '<br/><small>' . $featimg . '</small></p>';
                }
            }
            $html .= '</li>';
        }
        $html .= '</ol></div><!-- END posts to fix --><br/>';
        $html .= "\n\t\t\t<script type='text/javascript'>\n\t\t\tjQuery(document).ready(function() {\n\t\t\t\tjQuery('#fix-types a').click(function(){\n\t\t\t\t\tjQuery('.fix-all').fadeOut();\n\t\t\t\t\tjQuery('.' + jQuery(this).attr('id')).fadeIn();\n\t\t\t\t});\n\t\t\t});\n\t\t\t</script>\n\t\t";
        $idstofix = array();
        foreach ($themify_postfix as $post) {
            $idstofix[] = $post->ID;
        }
        /////////////////////////////////////////////////////////////
        // THIS IS JUST TO MAKE IT FAIL SO WE CAN SEE THE OUTPUT!! //
        $themify_postfix[] = '';
        // IT MUST BE REMOVED FOR PRODUCTION                       //
        /////////////////////////////////////////////////////////////
        if (empty($themify_postfix)) {
            echo 'true';
            die;
        } else {
            echo json_encode(array('collectedposts' => $html, 'idstofix' => $idstofix));
        }
        die;
    }
 /**
  * Add custom link actions in post / page rows
  * @param array $actions 
  * @return array
  */
 function row_actions($actions)
 {
     global $post;
     $builder_link = sprintf('<a href="%s" target="_blank">%s</a>', esc_url(get_permalink($post->ID) . '#builder_active'), __('Themify Builder', 'themify'));
     if ($this->layout->post_type_name == get_post_type() || $this->layout_part->post_type_name == get_post_type()) {
         $actions['themify-builder-duplicate'] = sprintf('<a href="%s">%s</a>', wp_nonce_url(admin_url('post.php?post=' . $post->ID . '&action=duplicate_tbuilder'), 'duplicate_themify_builder'), __('Duplicate', 'themify'));
         $actions['themify-builder'] = $builder_link;
     } else {
         // print builder links on another post types
         $registered_post_types = themify_post_types();
         if (in_array(get_post_type(), $registered_post_types)) {
             $actions['themify-builder'] = $builder_link;
         }
     }
     return $actions;
 }
 /**
  * Load admin js and css
  * @param $hook
  */
 function load_admin_js_css($hook)
 {
     global $pagenow, $current_screen;
     if (in_array($hook, array('post-new.php', 'post.php')) && in_array(get_post_type(), themify_post_types())) {
         wp_enqueue_style('themify-builder-main', THEMIFY_BUILDER_URI . '/css/themify-builder-main.css', array(), THEMIFY_VERSION);
         wp_enqueue_style('themify-builder-admin-ui', THEMIFY_BUILDER_URI . '/css/themify-builder-admin-ui.css', array(), THEMIFY_VERSION);
         if (is_rtl()) {
             wp_enqueue_style('themify-builder-admin-ui-rtl', THEMIFY_BUILDER_URI . '/css/themify-builder-admin-ui-rtl.css', array('themify-builder-admin-ui'), THEMIFY_VERSION);
         }
         //Enqueue jquery ui script
         wp_enqueue_script('jquery-ui-accordion');
         wp_enqueue_script('jquery-ui-droppable');
         wp_enqueue_script('jquery-ui-sortable');
         wp_register_script('themify-builder-admin-ui-js', THEMIFY_BUILDER_URI . "/js/themify.builder.admin.ui.js", array('jquery'), THEMIFY_VERSION, true);
         wp_enqueue_script('themify-builder-plugins-js');
         wp_enqueue_script('themify-builder-admin-ui-js');
         wp_localize_script('themify-builder-admin-ui-js', 'themifyBuilder', apply_filters('themify_builder_ajax_admin_vars', array('ajaxurl' => admin_url('admin-ajax.php'), 'tfb_load_nonce' => wp_create_nonce('tfb_load_nonce'), 'tfb_url' => THEMIFY_BUILDER_URI, 'dropPlaceHolder' => __('drop module here', 'themify'), 'newRowTemplate' => $this->template_vars['rows']['content'], 'draggerTitleMiddle' => __('Drag left/right to change columns', 'themify'), 'draggerTitleLast' => __('Drag left to add columns', 'themify'), 'confirm_on_duplicate_page' => __('Save the Builder before duplicating this page?', 'themify'))));
     }
 }