Example #1
0
/**
 * Init functions for post edit pages.
 *
 * Core function. Works and stable. Do not move or change.
 * If required, add hooks only.
 *
 * @param type $post
 */
function wpcf_admin_post_init($post)
{
    add_action('admin_footer', 'wpcf_admin_fields_postfields_styles');
    wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\'');
    wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\'');
    // Get post_type
    $post_type = wpcf_admin_get_edited_post_type($post);
    /*
     *
     * This is left to maintain compatibility with older versions
     * TODO Remove
     */
    // Add items to View dropdown
    if (in_array($post_type, array('view', 'view-template', 'cred-form'))) {
        add_filter('editor_addon_menus_wpv-views', 'wpcf_admin_post_editor_addon_menus_filter');
        add_action('admin_footer', 'wpcf_admin_post_js_validation');
        wpcf_enqueue_scripts();
        wp_enqueue_script('toolset-colorbox');
        wp_enqueue_style('toolset-colorbox');
    }
    // Never show on 'Views' and 'View Templates'
    if (in_array($post_type, array('view', 'view-template'))) {
        return false;
    }
    // Add marketing box
    if (!in_array($post_type, array('post', 'page', 'cred-form')) && !defined('WPCF_RUNNING_EMBEDDED')) {
        $hide_help_box = true;
        $help_box = wpcf_get_settings('help_box');
        $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
        if ($help_box != 'no') {
            if ($help_box == 'by_types' && array_key_exists($post_type, $custom_types)) {
                $hide_help_box = false;
            }
            if (function_exists('wprc_is_logged_to_repo') && wprc_is_logged_to_repo(WPCF_REPOSITORY)) {
                $hide_help_box = true;
            }
            if ($help_box == 'all') {
                $hide_help_box = false;
            }
            if (!$hide_help_box && !defined('WPV_VERSION')) {
                add_meta_box('wpcf-marketing', __('Display Custom Content', 'wpcf'), 'wpcf_admin_post_marketing_meta_box', $post_type, 'side', 'high');
            }
        }
    }
    // Are Types active?
    $wpcf_active = false;
    // Get groups
    $groups = wpcf_admin_post_get_post_groups_fields($post);
    foreach ($groups as $group) {
        $only_preview = '';
        //If Access plugin activated
        if (function_exists('wpcf_access_register_caps')) {
            //If user can't view own profile fields
            if (!current_user_can('view_fields_in_edit_page_' . $group['slug'])) {
                continue;
            }
            //If user can modify current group in own profile
            if (!current_user_can('modify_fields_in_edit_page_' . $group['slug'])) {
                $only_preview = 1;
            }
        }
        if (!empty($group['fields']) && empty($only_preview)) {
            $wpcf_active = true;
            break;
        }
    }
    // Activate scripts
    if ($wpcf_active) {
        add_action('admin_head', 'wpcf_post_preview_warning');
        wpcf_edit_post_screen_scripts();
    }
    // Add validation
    add_action('admin_footer', 'wpcf_admin_post_js_validation');
    /*
     * TODO Review
     * This is forced because of various Child cases
     * and when field are rendered via AJAX but not registered yet.
     *
     * Basically all fields that require additional JS should be added here.
     *
     * This is a must for now.
     * These fields need init JS in various cases.
     */
    wpcf_field_enqueue_scripts('date');
    wpcf_field_enqueue_scripts('image');
    wpcf_field_enqueue_scripts('file');
    wpcf_field_enqueue_scripts('skype');
    wpcf_field_enqueue_scripts('numeric');
    do_action('wpcf_admin_post_init', $post_type, $post, $groups, $wpcf_active);
}
Example #2
0
                        <a href="http://wp-types.com/home/views-create-elegant-displays-for-your-content/?utm_source=typesplugin&utm_medium=plugin&utm_term=meetviews&utm_content=promobox4&utm_campaign=types" target="_blank" class="button-primary" title="<?php 
    _e('Meet Views', 'wpcf');
    ?>
"><?php 
    _e('Meet Views', 'wpcf');
    ?>
</a>&nbsp;&nbsp;<a href="http://wp-types.com/free-trial/?utm_source=typesplugin&utm_medium=plugin&utm_term=freetrial&utm_content=promobox4&utm_campaign=types" target="_blank" class="button-secondary"><?php 
    _e('Free Trial', 'wpcf');
    ?>
</a>&nbsp;&nbsp;<a href="http://wp-types.com/buy/?utm_source=typesplugin&utm_medium=plugin&utm_term=pricing&utm_content=promobox4&utm_campaign=types" target="_blank" class="button-secondary" title="<?php 
    _e('Pricing', 'wpcf');
    ?>
"><?php 
    _e('Pricing', 'wpcf');
    ?>
</a>
                    </div>
                </div>
            </div>
        </div> 
    </div>

    <?php 
}
if (function_exists('wprc_is_logged_to_repo') && !wprc_is_logged_to_repo(WPCF_REPOSITORY)) {
    echo '<p>' . sprintf(__('Already purchased our Toolset package? %sLog-in to wp-types.com%s to remove this information box.', 'wpcf'), '<a href="' . admin_url('options-general.php?page=installer/pages/repositories.php') . '">', '</a>') . '</p>';
} else {
    if (!function_exists('wprc_is_logged_to_repo')) {
        echo '<p>' . sprintf(__('Already purchased our Toolset package? Install our Installer plugin and login to wp-types to remove this information box. %sInstructions &raquo;%s', 'wpcf'), '<a href="http://wp-types.com/documentation/installation/#2" target="_blank">', '</a>') . '</p>';
    }
}
Example #3
0
/**
 * Init functions for post edit pages.
 * 
 * Core function. Works and stable. Do not move or change.
 * If required, add hooks only.
 * 
 * @param type $upgrade 
 */
function wpcf_admin_post_init($post = false)
{
    global $wpcf;
    wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\'');
    wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\'');
    // Get post_type
    if ($post) {
        $post_type = get_post_type($post);
    } else {
        if (!isset($_GET['post_type'])) {
            $post_type = 'post';
        } else {
            if (in_array($_GET['post_type'], get_post_types(array('show_ui' => true)))) {
                $post_type = $_GET['post_type'];
            } else {
                return false;
            }
        }
    }
    // Set global $wpcf post object
    // CHECKPOINT
    $wpcf->post = $post;
    $wpcf->post_types->set($post_type);
    // Add items to View dropdown
    if (in_array($post_type, array('view', 'view-template'))) {
        add_filter('editor_addon_menus_wpv-views', 'wpcf_admin_post_editor_addon_menus_filter');
        add_action('admin_footer', 'wpcf_admin_post_js_validation');
        wpcf_enqueue_scripts();
    }
    // Never show on 'Views' and 'View Templates'
    // CRED should pass this check
    if (in_array($post_type, array('view', 'view-template'))) {
        return false;
    }
    // Add marketing box
    if (!in_array($post_type, array('post', 'page', 'cred-form')) && !defined('WPCF_RUNNING_EMBEDDED')) {
        $hide_help_box = true;
        $help_box = wpcf_get_settings('help_box');
        $custom_types = get_option('wpcf-custom-types', array());
        if ($help_box != 'no') {
            if ($help_box == 'by_types' && array_key_exists($post_type, $custom_types)) {
                $hide_help_box = false;
            }
            if (function_exists('wprc_is_logged_to_repo') && wprc_is_logged_to_repo(WPCF_REPOSITORY)) {
                $hide_help_box = true;
            }
            if ($help_box == 'all') {
                $hide_help_box = false;
            }
            if (!$hide_help_box) {
                add_meta_box('wpcf-marketing', __('Display Custom Content', 'wpcf'), 'wpcf_admin_post_marketing_meta_box', $post_type, 'side', 'high');
            }
        }
    }
    // Are Types active?
    $wpcf_active = false;
    // Get groups
    $groups = wpcf_admin_post_get_post_groups_fields($post);
    foreach ($groups as $group) {
        if (!empty($group['fields'])) {
            $wpcf_active = true;
            // Process fields
            $group['fields'] = wpcf_admin_post_process_fields($post, $group['fields'], true);
        }
        // Specially for CRED
        /*
         * 
         * TODO Setting some specific for CRED is wrong
         * Use hooks
         */
        if (!in_array($post_type, array('cred-form'))) {
            // Add meta boxes
            add_meta_box($group['slug'], wpcf_translate('group ' . $group['id'] . ' name', $group['name']), 'wpcf_admin_post_meta_box', $post_type, $group['meta_box_context'], 'high', $group);
        }
    }
    // Activate scripts
    if ($wpcf_active) {
        wp_enqueue_script('wpcf-fields-post', WPCF_EMBEDDED_RES_RELPATH . '/js/fields-post.js', array('jquery'), WPCF_VERSION);
        wp_enqueue_script('wpcf-form-validation', WPCF_EMBEDDED_RES_RELPATH . '/js/' . 'jquery-form-validation/jquery.validate.min.js', array('jquery'), WPCF_VERSION);
        wp_enqueue_script('wpcf-form-validation-additional', WPCF_EMBEDDED_RES_RELPATH . '/js/' . 'jquery-form-validation/additional-methods.min.js', array('jquery'), WPCF_VERSION);
        wp_enqueue_style('wpcf-fields-basic', WPCF_EMBEDDED_RES_RELPATH . '/css/basic.css', array(), WPCF_VERSION);
        wp_enqueue_style('wpcf-fields-post', WPCF_EMBEDDED_RES_RELPATH . '/css/fields-post.css', array('wpcf-fields-basic'), WPCF_VERSION);
        wpcf_enqueue_scripts();
    }
    // Add validation
    // TODO Move to wpcf_enqueue_scripts()
    add_action('admin_footer', 'wpcf_admin_post_js_validation');
    do_action('wpcf_admin_post_init', $post_type, $post, $groups, $wpcf_active);
}