Example #1
0
function hocwp_meta_box_editor($args = array())
{
    global $pagenow;
    if ('post-new.php' == $pagenow || 'post.php' == $pagenow) {
        $post_type = hocwp_get_value_by_key($args, 'post_type');
        if (!is_array($post_type)) {
            $post_type = array($post_type);
        }
        $box_title = hocwp_get_value_by_key($args, 'title', __('Additional Information', 'hocwp-theme'));
        $current_type = hocwp_get_current_post_type();
        if (is_array($current_type)) {
            $current_type = current($current_type);
        }
        $box_id = hocwp_get_value_by_key($args, 'id');
        if (empty($box_id)) {
            $box_id = hocwp_sanitize_id($box_title);
            if (empty($box_id)) {
                return;
            }
        }
        if (!empty($current_type)) {
            $box_id = $current_type . '_' . $box_id;
        }
        $field_args = hocwp_get_value_by_key($args, 'field_args', array());
        $field_args = hocwp_sanitize_array($field_args);
        $field_args['field_callback'] = 'hocwp_field_editor';
        $field_args['label'] = '';
        $field_id = hocwp_get_value_by_key($args, 'field_id', hocwp_get_value_by_key($field_args, 'field_id'));
        $field_name = hocwp_get_value_by_key($args, 'field_name', hocwp_get_value_by_key($field_args, 'field_name'));
        hocwp_transmit_id_and_name($field_id, $field_name);
        if (empty($field_id)) {
            return;
        }
        $field_args['id'] = $field_id;
        $field_args['name'] = $field_name;
        $meta = new HOCWP_Meta('post');
        $meta->set_title($box_title);
        $meta->set_id($box_id);
        $meta->set_post_types($post_type);
        $meta->add_field($field_args);
        $meta->init();
    }
}
    public function post_meta_box_callback()
    {
        $class = 'hocwp-meta-box';
        hocwp_add_string_with_space_before($class, $this->get_context());
        hocwp_add_string_with_space_before($class, $this->get_priority());
        foreach ($this->get_post_types() as $post_type) {
            hocwp_add_string_with_space_before($class, 'post-type-' . $post_type);
        }
        ?>
		<div class="<?php 
        echo $class;
        ?>
">
			<?php 
        if (hocwp_callback_exists($this->get_callback())) {
            call_user_func($this->get_callback());
        } else {
            global $post;
            $post_id = $post->ID;
            foreach ($this->get_fields() as $field) {
                $field_args = isset($field['field_args']) ? $field['field_args'] : array();
                $callback = isset($field['field_callback']) ? $field['field_callback'] : 'hocwp_field_input';
                if (!isset($field_args['value'])) {
                    $name = $field_args['name'];
                    $value = hocwp_get_post_meta($name, $post_id);
                    $field_args['value'] = $value;
                }
                if (hocwp_callback_exists($callback)) {
                    call_user_func($callback, $field_args);
                } else {
                    echo '<p>' . sprintf(__('The callback function %s does not exists!', 'hocwp-theme'), '<strong>' . $callback . '</strong>') . '</p>';
                }
            }
        }
        do_action('hocwp_post_meta_box_field', $this);
        $current_post_type = hocwp_get_current_post_type();
        if (!empty($current_post_type)) {
            do_action('hocwp_' . $current_post_type . '_meta_box_field');
        }
        do_action('hocwp_meta_box_' . $this->get_id() . '_field');
        ?>
		</div>
		<?php 
    }
Example #3
0
            $meta->add_field($field_args);
        }
        $meta->add_field(array('id' => 'expire', 'label' => __('Expire:', 'hocwp-theme'), 'field_callback' => 'hocwp_field_datetime_picker'));
        do_action('hocwp_meta_box_ads_fields', $meta, $post);
        $meta->init();
        $args = array('id' => 'code_box', 'title' => __('Code:', 'hocwp-theme'), 'field_id' => 'code', 'post_type' => $post_type, 'field_args' => array('teeny' => true));
        hocwp_meta_box_editor($args);
    }
}
if (!hocwp_is_post($post)) {
    if ('post.php' == $pagenow) {
        $post_id = hocwp_get_method_value('post', 'get');
        $post = get_post($post_id);
    }
}
$post_type = hocwp_get_current_post_type();
if ('post.php' == $pagenow || 'post-new.php' == $pagenow) {
    if (!hocwp_is_post($post)) {
        $current_post = hocwp_get_current_new_post();
        if (hocwp_is_post($current_post)) {
            $post = $current_post;
        }
    }
    hocwp_meta_box_page_additional_information();
    hocwp_meta_box_side_image(array('post_type' => 'all', 'id' => 'hocwp_large_thumbnail_box', 'title' => __('Large Thumbnail', 'hocwp-theme'), 'field_id' => 'large_thumbnail'));
    hocwp_theme_meta_box_sidebar_information($post_type, $post);
    hocwp_theme_meta_box_subscriber_information($post_type, $post);
}
function hocwp_theme_meta_boxes_init($post_type, $post)
{
    hocwp_slider_meta_box_field($post_type, $post);
function hocwp_classifieds_admin_init()
{
    global $pagenow;
    $role = get_role('subscriber');
    if (hocwp_object_valid($role)) {
        $role->add_cap('publish_posts');
        $role->add_cap('edit_posts');
    }
    if ('post-new.php' == $pagenow) {
        if (hocwp_is_subscriber()) {
            $post_type = hocwp_get_current_post_type();
            if (!empty($post_type) && 'post' !== $post_type) {
                wp_redirect(admin_url());
                exit;
            }
        }
    }
}
Example #5
0
function hocwp_get_current_new_post()
{
    global $pagenow;
    $result = null;
    if ('post-new.php' == $pagenow) {
        $query_args = array('post_status' => 'auto-draft', 'orderby' => 'date', 'order' => 'desc', 'posts_per_page' => 1, 'cache' => false);
        $post_type = hocwp_get_current_post_type();
        if (!empty($post_type)) {
            $query_args['post_type'] = $post_type;
        }
        $query = hocwp_query($query_args);
        $result = array_shift($query->posts);
    }
    return $result;
}
function hocwp_setup_theme_admin_parent_file()
{
    global $pagenow;
    if ('post-new.php' == $pagenow || 'post.php' == $pagenow || 'edit.php' == $pagenow) {
        global $hocwp_private_post_types;
        $post_type = hocwp_get_current_post_type();
        if (is_array($hocwp_private_post_types) && in_array($post_type, $hocwp_private_post_types)) {
            global $parent_file, $submenu_file;
            $parent_file = 'hocwp_private_types';
            $submenu_file = 'edit.php?post_type=' . $post_type;
            $script = 'jQuery(document).ready(function($) {';
            $script .= '$(\'#toplevel_page_' . $parent_file . ', #toplevel_page_' . $parent_file . ' > a\').removeClass(\'wp-not-current-submenu\').addClass(\'wp-has-current-submenu\');';
            $script .= '});';
            hocwp_inline_script($script);
        }
    }
}