/**
 * After Save Event
 *
 * This runs after the event post is saved, for further manipulation of meta data.
 *
 * @since 1.2
 * @param int $post_id Post ID
 * @param object $post Data for post being saved
 */
function ctc_after_save_event($post_id, $post)
{
    // Event is being saved
    if (!isset($post->post_type) || 'ctc_event' != $post->post_type) {
        return;
    }
    // Is a POST occurring?
    if (empty($_POST)) {
        return;
    }
    // Not an auto-save (meta values not submitted)
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    // Verify the nonce
    $nonce_key = 'ctc_event_date_nonce';
    $nonce_action = 'ctc_event_date_save';
    if (empty($_POST[$nonce_key]) || !wp_verify_nonce($_POST[$nonce_key], $nonce_action)) {
        return;
    }
    // Make sure user has permission to edit
    $post_type = get_post_type_object($post->post_type);
    if (!current_user_can($post_type->cap->edit_post, $post_id)) {
        return;
    }
    // Action hook
    do_action('ctc_after_save_event', $post_id, $post);
}
 function flt_adjust_reqd_caps($reqd_caps, $orig_cap, $user_id, $args)
 {
     global $pagenow, $current_user;
     // Work around WP's occasional use of literal 'cap_name' instead of $post_type_object->cap->$cap_name
     // note: cap names for "post" type may be customized too
     if (in_array($pagenow, array('edit.php', 'post.php', 'post-new.php', 'press-this.php', 'admin-ajax.php', 'upload.php', 'media.php')) && in_array('edit_posts', $reqd_caps) && $user_id == $current_user->ID && !$this->doing_admin_menus()) {
         static $did_admin_init = false;
         if (!$did_admin_init) {
             $did_admin_init = did_action('admin_init');
         }
         if ($did_admin_init) {
             if (!empty($args[0])) {
                 $item_id = is_object($args[0]) ? $args[0]->ID : $args[0];
             } else {
                 $item_id = 0;
             }
             if ($type_obj = get_post_type_object(pp_find_post_type($item_id))) {
                 $key = array_search('edit_posts', $reqd_caps);
                 if (false !== $key) {
                     $reqd_caps[$key] = $type_obj->cap->edit_posts;
                 }
             }
         }
     }
     //===============================
     return $reqd_caps;
 }
/**
 * Appends an "active_section" property to every post being returned during bu_navigation_get_pages
 *
 * @param array $pages Associative array of pages keyed on page ID
 * @return array Filtered associative array of pages with active_section member variable set
 */
function bu_navigation_filter_pages_ancestors($pages)
{
    global $wpdb, $post;
    // Only useful during single post query
    if (!$post) {
        return $pages;
    }
    // Only needed for hierarchical post types
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object->hierarchical) {
        return $pages;
    }
    $ancestors = bu_navigation_gather_sections($post->ID, array('post_types' => $post->post_type));
    $filtered = array();
    if (is_array($pages) && count($pages) > 0) {
        if (is_array($ancestors) && count($ancestors) > 0) {
            foreach ($pages as $page) {
                $page->active_section = false;
                if (in_array($page->ID, $ancestors) && $page->ID != $post->ID) {
                    $page->active_section = true;
                }
                $filtered[$page->ID] = $page;
            }
        } else {
            $filtered = $pages;
        }
    }
    return $filtered;
}
Example #4
0
 public static function savemeta($post_id, $post)
 {
     /* Get the post type object. */
     $post_type = get_post_type_object($post->post_type);
     /* Check if the current user has permission to edit the post. */
     if (!current_user_can($post_type->cap->edit_post, $post_id)) {
         return $post_id;
     }
     /* Get the meta key. */
     $meta_key = self::$prefix . $post_id;
     /* Get the posted data and sanitize it for use as an HTML class. */
     $new_meta_value = isset($_POST[self::$prefix]) ? $_POST[self::$prefix] : '';
     /* Get the meta value of the custom field key. */
     $meta_value = get_post_meta($post_id, $meta_key, true);
     /* If a new meta value was added and there was no previous value, add it. */
     if ($new_meta_value && '' == $meta_value) {
         add_post_meta($post_id, $meta_key, $new_meta_value, true);
     } elseif ($new_meta_value && $new_meta_value != $meta_value) {
         update_post_meta($post_id, $meta_key, $new_meta_value);
     } elseif ('' == $new_meta_value && $meta_value) {
         delete_post_meta($post_id, $meta_key, $meta_value);
         if (($ptemplate = self::getPathTheme($post_id)) && file_exists($ptemplate)) {
             unlink($ptemplate);
         }
     }
 }
 public static function query_posts($request = null)
 {
     $response = (object) array('status' => false, 'message' => __('Your request has failed', 'fakerpress'), 'results' => array(), 'more' => true);
     if (!Admin::$is_ajax && is_null($request) || !is_user_logged_in()) {
         return Admin::$is_ajax ? exit(json_encode($response)) : $response;
     }
     $request = (object) $_POST;
     if (isset($request->query['post_type']) && !is_array($request->query['post_type'])) {
         $request->query['post_type'] = array_map('trim', (array) explode(',', $request->query['post_type']));
     }
     $query = new \WP_Query($request->query);
     if (!$query->have_posts()) {
         return Admin::$is_ajax ? exit(json_encode($response)) : $response;
     }
     $response->status = true;
     $response->message = __('Request successful', 'fakerpress');
     foreach ($query->posts as $k => $post) {
         $query->posts[$k]->post_type = get_post_type_object($post->post_type);
     }
     $response->results = $query->posts;
     if ($query->max_num_pages >= $request->query['paged']) {
         $response->more = false;
     }
     return Admin::$is_ajax ? exit(json_encode($response)) : $response;
 }
 function flt_get_editable_authors($unfiltered_results)
 {
     global $wpdb, $scoper, $post;
     if (!($post_type = cr_find_post_type())) {
         return $unfiltered_results;
     }
     if (!($post_type_obj = get_post_type_object($post_type))) {
         return $unfiltered_results;
     }
     $have_cap = cr_user_can($post_type_obj->cap->edit_others_posts, $post->ID, 0, array('require_full_object_role' => true));
     if ($have_cap) {
         return $scoper->users_who_can($post_type_obj->cap->edit_posts, COLS_ALL_RS);
     } else {
         if ($post->ID) {
             if ($current_author = $scoper->data_sources->get_from_db('owner', 'post', $post->ID)) {
                 $force_user_id = $current_author;
             }
         } else {
             global $current_user;
             $force_user_id = $current_user->ID;
         }
         if ($force_user_id) {
             $display_name = $wpdb->get_var("SELECT display_name FROM {$wpdb->users} WHERE ID = '{$force_user_id}'");
             $users = array((object) array('ID' => $force_user_id, 'display_name' => $display_name));
             return $users;
         }
     }
     //log_mem_usage_rs( 'flt_get_editable_authors()' );
     return $unfiltered_results;
 }
Example #7
0
/**
 * Saves the video embed code on post save
 *
 * @since 4.0
 */
function medium_save_video_meta($post_id)
{
    global $post;
    // Return early if this is a newly created post that hasn't been saved yet.
    if ('auto-draft' == get_post_status($post_id)) {
        return $post_id;
    }
    // Check if the user intended to change this value.
    if (!isset($_POST['medium_video_box_nonce']) || !wp_verify_nonce($_POST['medium_video_box_nonce'], plugin_basename(__FILE__))) {
        return $post_id;
    }
    // Get post type object
    $post_type = get_post_type_object($post->post_type);
    // Check if user has permission
    if (!current_user_can($post_type->cap->edit_post, $post_id)) {
        return $post_id;
    }
    // Get posted data and sanitize it
    $new_video = isset($_POST['medium_video_field']) ? $_POST['medium_video_field'] : '';
    // Get existing video
    $video = get_post_meta($post_id, 'video', true);
    // If a new video was submitted and there was no previous one, add it
    if ($new_video && '' == $video) {
        add_post_meta($post_id, 'video', $new_video, true);
    } elseif ($new_video && $new_video != $video) {
        update_post_meta($post_id, 'video', $new_video);
    } elseif ('' == $new_video && $video) {
        delete_post_meta($post_id, 'video', $video);
    }
}
Example #8
0
/**
 * Render Popup Columns
 *
 * @since 1.0
 *
 * @param string $column_name Column name
 * @param int $post_id Popup (Post) ID
 *
 * @return void
 */
function popmake_render_popup_columns($column_name, $post_id)
{
    if (get_post_type($post_id) == 'popup') {
        global $popmake_options;
        $post = get_post($post_id);
        setup_postdata($post);
        $post_type_object = get_post_type_object($post->post_type);
        $can_edit_post = current_user_can($post_type_object->cap->edit_post, $post->ID);
        switch ($column_name) {
            case 'popup_title':
                echo '<strong>' . esc_html(popmake_get_the_popup_title($post_id)) . '</strong>';
                break;
            case 'popup_category':
                echo get_the_term_list($post_id, 'popup_category', '', ', ', '');
                break;
            case 'popup_tag':
                echo get_the_term_list($post_id, 'popup_tag', '', ', ', '');
                break;
            case 'class':
                echo '<pre style="display:inline-block;margin:0;"><code>popmake-' . absint($post_id) . '</code></pre>';
                if ($post->post_name != $post->ID) {
                    echo '|';
                    echo '<pre style="display:inline-block;margin:0;"><code>popmake-' . $post->post_name . '</code></pre>';
                }
                break;
        }
    }
}
Example #9
0
function my_init()
{
    $args = objectToArray(get_post_type_object('post'));
    $args['has_archive'] = 'news';
    $args['rewrite'] = array('slug' => 'news', 'with_front' => false);
    register_post_type('post', $args);
}
function bogo_post_row_actions($actions, $post)
{
    if (!bogo_is_localizable_post_type($post->post_type)) {
        return $actions;
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!current_user_can($post_type_object->cap->edit_post, $post->ID) || 'trash' == $post->post_status) {
        return $actions;
    }
    $user_locale = bogo_get_user_locale();
    $post_locale = bogo_get_post_locale($post->ID);
    if ($user_locale == $post_locale) {
        return $actions;
    }
    $translations = bogo_get_post_translations($post);
    if (!empty($translations[$user_locale])) {
        $translation = $translations[$user_locale];
        if (empty($translation->ID) || $translation->ID == $post->ID) {
            return $actions;
        }
        $title = __('Edit %s translation of this item', 'bogo');
        $text = __('Edit %s translation', 'bogo');
        $edit_link = get_edit_post_link($translation->ID);
    } else {
        $title = __('Translate this item into %s', 'bogo');
        $text = __('Translate into %s', 'bogo');
        $edit_link = admin_url('post-new.php?post_type=' . $post->post_type . '&locale=' . $user_locale . '&original_post=' . $post->ID);
    }
    $language = bogo_get_language($user_locale);
    if (empty($language)) {
        $language = $user_locale;
    }
    $actions['translate'] = '<a title="' . esc_attr(sprintf($title, $language)) . '" href="' . $edit_link . '">' . esc_html(sprintf($text, $language)) . '</a>';
    return $actions;
}
Example #11
0
 /**
  * Creates cloned landing page and opens it for user
  * @param string $status
  */
 public static function clone_landing_page($status = 'pending')
 {
     /* Get the original post */
     $id = isset($_GET['post']) ? $_GET['post'] : $_POST['post'];
     $post = get_post($id);
     /* Copy the post and insert it */
     if (!isset($post) || !$post) {
         $post_type_obj = get_post_type_object($post->post_type);
         wp_die(esc_attr(__('Copy creation failed, could not find original:', 'landing-pages')) . ' ' . $id);
     }
     if (!is_object($post) && is_numeric($post)) {
         $post = get_post($post);
     }
     $status = $post->post_status;
     /* We don't want to clone revisions */
     if ($post->post_type == 'revision') {
         return;
     }
     $prefix = "Copy of ";
     $suffix = "";
     $status = 'pending';
     $new_post_author = self::get_current_user();
     $new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author->ID, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_mime_type' => $post->post_mime_type, 'post_parent' => $new_post_parent = empty($parent_id) ? $post->post_parent : $parent_id, 'post_password' => $post->post_password, 'post_status' => $status, 'post_title' => $prefix . $post->post_title . $suffix, 'post_type' => $post->post_type);
     $new_post['post_date'] = $new_post_date = $post->post_date;
     $new_post['post_date_gmt'] = get_gmt_from_date($new_post_date);
     $new_post_id = wp_insert_post($new_post);
     $meta_data = self::get_meta($post->ID);
     foreach ($meta_data as $key => $value) {
         update_post_meta($new_post_id, $key, $value);
     }
     wp_redirect(admin_url('edit.php?post_type=' . $post->post_type));
     exit;
 }
Example #12
0
 /**
  * Normalize parameters for field
  *
  * @param array $field
  *
  * @return array
  */
 static function normalize($field)
 {
     /**
      * Set default field args
      */
     $field = wp_parse_args($field, array('post_type' => 'post', 'field_type' => 'select', 'parent' => false, 'query_args' => array()));
     /**
      * Set default placeholder
      * - If multiple post types: show 'Select a post'
      * - If single post type: show 'Select a %post_type_name%'
      */
     if (empty($field['placeholder'])) {
         $field['placeholder'] = __('Select a post', 'meta-box');
         if (is_string($field['post_type']) && post_type_exists($field['post_type'])) {
             $post_type_object = get_post_type_object($field['post_type']);
             $field['placeholder'] = sprintf(__('Select a %s', 'meta-box'), $post_type_object->labels->singular_name);
         }
     }
     /**
      * Set parent option, which will change field name to `parent_id` to save as post parent
      */
     if ($field['parent']) {
         $field['multiple'] = false;
         $field['field_name'] = 'parent_id';
     }
     /**
      * Set default query args
      */
     $field['query_args'] = wp_parse_args($field['query_args'], array('post_status' => 'publish', 'posts_per_page' => -1));
     $field['query_args']['post_type'] = $field['post_type'];
     $field = parent::normalize($field);
     return $field;
 }
 function flt_defeat_publish_filter($where)
 {
     $post_type = cr_find_post_type();
     $post_type_obj = get_post_type_object($post_type);
     $object_id = scoper_get_object_id('post', $post_type);
     // don't alter the query if RS query filtering is disabled, or if this maneuver has been disabled via constant
     // note: for non-administrators, QueryInterceptor_RS::flt_objects_where will convert the publish requirement to publish OR private, if the user's blog role or RS-assigned roles grant private access
     if (!is_content_administrator_rs() || defined('SCOPER_RETAIN_PUBLISH_FILTER') || defined('DISABLE_QUERYFILTERS_RS')) {
         return $where;
     }
     global $wp_query;
     if (is_admin() && !empty($wp_query->query['post_status'])) {
         // if a specific status was requested by URI, don't force inclusion of others
         return $where;
     }
     // don't alter the where clause if in wp-admin and not filtering by taxonomy
     if (is_admin()) {
         global $wp_query;
         if (empty($wp_query) && empty($wp_query->is_tax)) {
             return $where;
         }
     }
     global $wpdb, $current_user;
     // don't alter the where clause for anonymous users
     if (empty($current_user->ID)) {
         return $where;
     }
     $where = preg_replace("/{$wpdb->posts}.post_status\\s*=\\s*'publish'/", "({$wpdb->posts}.post_status = 'publish' OR {$wpdb->posts}.post_status = 'private')", $where);
     $where = preg_replace("/p2.post_status\\s*=\\s*'publish'/", "(p2.post_status = 'publish' OR p2.post_status = 'private')", $where);
     $where = preg_replace("/p.post_status\\s*=\\s*'publish'/", "(p.post_status = 'publish' OR p.post_status = 'private')", $where);
     return $where;
 }
Example #14
0
/**
 * SAVE metaboxes for SEO
 */
function copernico_save_seo_post_meta($post_id, $post)
{
    /* 
     * Security checks
     */
    if (!isset($_POST['copernico_metabox_nonce']) || !wp_verify_nonce($_POST['copernico_metabox_nonce'], basename(__FILE__))) {
        return $post_id;
    }
    /* 
     * Check current user permissions
     */
    $post_type = get_post_type_object($post->post_type);
    if (!current_user_can($post_type->cap->edit_post, $post_id)) {
        return $post_id;
    }
    /*
     * Do not save the data if autosave
     */
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    if ($post->post_type == 'post') {
        update_post_meta($post_id, 'copernico_seo_title', trim($_POST['copernico_seo_title']));
        //update_post_meta($post_id, 'rudr_noindex', $_POST['rudr_noindex']);
    }
    return $post_id;
}
 /**
  * TODO: Ability to set default values for:
  *
  * - Campaign type
  * - List, list segment
  * - Template
  */
 public function __construct($post_type = null)
 {
     $this->post_type = $post_type;
     $this->post_type_obj = get_post_type_object($this->post_type);
     $this->settings_key = $this->post_type_obj->name . '_mailchimp_settings';
     $this->init();
 }
/**
 * Saves the plugin info meta box.
 *
 * @since 0.1.0
 */
function themeist_plugins_save_plugin_info_meta_box($post_id, $post)
{
    if (!isset($_POST['themeist-plugin-info-meta-box']) || !wp_verify_nonce($_POST['themeist-plugin-info-meta-box'], basename(__FILE__))) {
        return $post_id;
    }
    $post_type = get_post_type_object($post->post_type);
    if (!current_user_can($post_type->cap->edit_post, $post_id)) {
        return $post_id;
    }
    $meta = array('plugin_download_url' => esc_attr(strip_tags($_POST['plugin-download-link'])), 'plugin_repo_url' => esc_url(strip_tags($_POST['plugin-repo-link'])), 'plugin_version_number' => strip_tags($_POST['plugin-version']));
    foreach ($meta as $meta_key => $new_meta_value) {
        /* Get the meta value of the custom field key. */
        $meta_value = get_post_meta($post_id, $meta_key, true);
        /* If a new meta value was added and there was no previous value, add it. */
        if (!empty($new_meta_value) && empty($meta_value)) {
            add_post_meta($post_id, $meta_key, $new_meta_value, true);
        } elseif ($new_meta_value !== $meta_value) {
            update_post_meta($post_id, $meta_key, $new_meta_value);
        } elseif ('' === $new_meta_value && !empty($meta_value)) {
            delete_post_meta($post_id, $meta_key, $meta_value);
        }
    }
    /* We need this b/c draft post's post_name don't get set. */
    $post_name = !empty($post->post_name) ? $post->post_name : sanitize_title($post->post_title);
    if (!term_exists("relationship-{$post_name}", 'doc_relationship')) {
        $args = array('slug' => "relationship-{$post_name}");
        $parent_term = get_term_by('slug', 'relationship-plugins', 'doc_relationship');
        if (!empty($parent_term)) {
            $args['parent'] = $parent_term->term_id;
        }
        wp_insert_term($post->post_title, 'doc_relationship', $args);
    }
}
/**
 * Add a checkbox to the post actions metabox
 *
 * @since 1.0.0
 */
function title_toggle_post_title_actions()
{
    global $post;
    $post_type = get_post_type_object($post->post_type);
    $hide_title = get_post_meta($post->ID, '_hide_title', true);
    ?>
	<div class="misc-pub-section columns-prefs">

		<?php 
    wp_nonce_field('title_toggle_post_title', 'title_toggle_post_title_nonce');
    ?>
					
		<label class="columns-prefs-1">
			<?php 
    printf(__('Hide %s title:', 'title-toggle'), strtolower($post_type->labels->singular_name));
    ?>
 <input type="checkbox" name="hide_title" value="1" <?php 
    checked($hide_title, '1');
    ?>
>
		</label>

	</div>
		<?php 
}
Example #18
0
    function republish_link()
    {
        global $post;
        $post_type_object = get_post_type_object($post->post_type);
        $can_publish = current_user_can($post_type_object->cap->publish_posts);
        if (!($can_publish && 'publish' == $post->post_status)) {
            return;
        }
        print <<<SCRIPT
<script>
jQuery(document).ready( function(\$) {
   \$('.cancel-timestamp').after('<a href="#republish" class="republish hide-if-no-js button-cancel">Set publish date to now</a>');
   \$('.republish').click( function( event ) {
      \$('#aa').val(\$('#cur_aa').val()); 
      \$('#mm').val(\$('#cur_mm').val()); 
      \$('#jj').val(\$('#cur_jj').val());
      \$('#hh').val(\$('#cur_hh').val());
      \$('#mn').val(\$('#cur_mn').val());    
\t   \$('.save-timestamp').click();
\t   pub = \$('#timestamp').find('b').html();
\t   pub = pub.replace(' : ',':');
\t   pub = pub.replace('@ ','@');
\t   if(\$.isNumeric(pub.charAt(0))) pub = pub.substring(3)
\t   \$('#timestamp').find('b').html(pub);
      });
   });
</script>
SCRIPT;
    }
Example #19
0
function kkthemes_archive_title()
{
    $tag_style = '';
    $header_image = get_header_image();
    if (!empty($header_image)) {
        $tag_style = 'background-image: url(' . esc_url($header_image) . ');';
    }
    ?>
	<div class="uk-panel uk-panel-box uk-panel-space uk-text-large uk-text-center tm-branded-panel uk-margin-large-bottom" style="<?php 
    echo $tag_style;
    ?>
">
		<h1 class="uk-article-title" itemprop="headline">
			<?php 
    single_cat_title('') || post_type_archive_title('');
    ?>
		</h1>
		<?php 
    if (is_featured_item()) {
        $post_type = get_post_type();
        echo '<p>' . get_post_type_object($post_type)->description . '</p>';
    } else {
        echo category_description();
    }
    ?>
	</div>
<?php 
}
 function smashing_save_post_class_meta($post_id, $post)
 {
     /* Verify the nonce before proceeding. */
     if (!isset($_POST['smashing_post_class_nonce']) || !wp_verify_nonce($_POST['smashing_post_class_nonce'], basename(__FILE__))) {
         return $post_id;
     }
     /* Get the post type object. */
     $post_type = get_post_type_object($post->post_type);
     /* Check if the current user has permission to edit the post. */
     if (!current_user_can($post_type->cap->edit_post, $post_id)) {
         return $post_id;
     }
     /* Get the posted data and sanitize it for use as an HTML class. */
     $new_meta_value = isset($_POST['smashing-post-class']) ? sanitize_html_class($_POST['smashing-post-class']) : '';
     /* Get the meta key. */
     $meta_key = 'smashing_post_class';
     /* Get the meta value of the custom field key. */
     $meta_value = get_post_meta($post_id, $meta_key, true);
     /* If a new meta value was added and there was no previous value, add it. */
     if ($new_meta_value && '' == $meta_value) {
         add_post_meta($post_id, $meta_key, $new_meta_value, true);
     } elseif ($new_meta_value && $new_meta_value != $meta_value) {
         update_post_meta($post_id, $meta_key, $new_meta_value);
     } elseif ('' == $new_meta_value && $meta_value) {
         delete_post_meta($post_id, $meta_key, $meta_value);
     }
 }
function comcon_meta_save()
{
    global $post;
    $post_id = $post->ID;
    if (!isset($_POST['comcon-form-nonce']) || !wp_verify_nonce($_POST['comcon-form-nonce'], basename(__FILE__))) {
        return $post->ID;
    }
    $post_type = get_post_type_object($post->post_type);
    if (!current_user_can($post_type->cap->edit_post, $post_id)) {
        return $post->ID;
    }
    $input = array();
    $input['position'] = isset($_POST['comcon-form-position']) ? $_POST['comcon-form-position'] : '';
    $input['major'] = isset($_POST['comcon-form-major']) ? $_POST['comcon-form-major'] : '';
    $input['order'] = str_pad($input['order'], 3, "0", STR_PAD_LEFT);
    foreach ($input as $field => $value) {
        $old = get_post_meta($post_id, 'comcon-form-' . $field, true);
        if ($value && '' == $old) {
            add_post_meta($post_id, 'comcon-form-' . $field, $value, true);
        } else {
            if ($value && $value != $old) {
                update_post_meta($post_id, 'comcon-form-' . $field, $value);
            } else {
                if ('' == $value && $old) {
                    delete_post_meta($post_id, 'comcon-form-' . $field, $old);
                }
            }
        }
    }
}
 /**
  * Summary.
  *
  * Description.
  *
  * @since x.x.x
  * @access (for functions: only use if private)
  *
  * @see Function/method/class relied on
  * @link URL
  * @global type $varname Description.
  * @global type $varname Description.
  *
  * @param type $var Description.
  * @param type $var Optional. Description.
  * @return type Description.
  */
 public function get_post_type($post_type_slug)
 {
     if (empty($post_type_slug)) {
         return wpcf_custom_types_default();
     }
     $post_type = array();
     $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
     if (isset($custom_types[$post_type_slug])) {
         $post_type = $custom_types[$post_type_slug];
         $post_type['update'] = true;
     } else {
         $buildin_post_types = wpcf_get_builtin_in_post_types();
         if (isset($buildin_post_types[$post_type_slug])) {
             $post_type = get_object_vars(get_post_type_object($post_type_slug));
             $post_type['labels'] = get_object_vars($post_type['labels']);
             $post_type['slug'] = esc_attr($post_type_slug);
             $post_type['_builtin'] = true;
         } else {
             return false;
         }
     }
     if (!isset($post_type['update'])) {
         $post_type['update'] = false;
     }
     return $post_type;
 }
 public static function save_post_meta_data($post_id, $post)
 {
     /* Verify the nonce before proceeding. */
     if (!isset($_POST['rating_form_meta_box_nonce']) || !wp_verify_nonce($_POST['rating_form_meta_box_nonce'], basename(__FILE__))) {
         return $post_id;
     }
     /* Get the post type object. */
     $post_type = get_post_type_object($post->post_type);
     /* Check if the current user has permission to edit the post. */
     if (!current_user_can($post_type->cap->edit_post, $post_id)) {
         return $post_id;
     }
     //echo '<pre>'; print_r($_POST); echo '</pre>'; die();
     /* Get the posted data and sanitize it for use as an HTML class. */
     $new_meta_enable_value = (isset($_POST['enable_ratingForm']) and $_POST['enable_ratingForm'] == 1) ? $_POST['enable_ratingForm'] : '0';
     $new_meta_default_ratingForm_value = (isset($_POST['is_default_ratingForm']) and $_POST['is_default_ratingForm'] == 1) ? $_POST['is_default_ratingForm'] : '0';
     $new_meta_listing_value = (isset($_POST['listing_ratingForm']) and $_POST['listing_ratingForm'] != '#NONE#') ? sanitize_html_class($_POST['listing_ratingForm']) : '';
     /* Get the meta key. */
     $meta_keys['_cbrating_enable_ratingForm'] = $new_meta_enable_value;
     $meta_keys['_cbrating_is_default_ratingForm'] = $new_meta_default_ratingForm_value;
     $meta_keys['_cbrating_listing_ratingForm'] = $new_meta_listing_value;
     foreach ($meta_keys as $meta_key => $new_meta_value) {
         $success = update_post_meta($post_id, $meta_key, $new_meta_value);
     }
 }
Example #24
0
 public function __construct($settings = array())
 {
     parent::__construct();
     // Make sure core is the correct version for this module.
     if (version_compare(icit_core::VERSION, self::VERSION, '<')) {
         error_log(sprintf(__('Wrong ICIT Core version. Class "%3$s" expecting core version version %2$s but got version %1$s in file %4$s', self::DOM), icit_core::VERSION, self::VERSION, __CLASS__, __FILE__), E_USER_WARNING);
         return false;
     }
     // Merge the settings passed in with the defaults
     $this->option_page_settings = wp_parse_args($settings, $this->option_page_settings);
     // Options page
     add_action('admin_menu', array($this, '_add_options_page'));
     // Set customiser
     if ($this->option_page_settings['use_customiser']) {
         add_action('customize_register', array($this, '_set_customiser'), 1);
     }
     // Add settings fields
     $register_settings_cb = is_callable($this->option_page_settings['register_settings']) ? $this->option_page_settings['register_settings'] : array($this, 'register_settings');
     add_action('admin_init', $register_settings_cb);
     if ($this->option_page_settings['use_customiser']) {
         add_action('customize_register', $register_settings_cb);
     }
     // Setup / get options page hidden post
     add_action('admin_init', array($this, '_set_options_post'));
     add_action('customize_register', array($this, '_set_options_post'));
     // Admin page scripts
     add_action('admin_enqueue_scripts', array($this, '_option_page_scripts'));
     // Option page posts, well and truly hidden away. Used to attach
     // images uploaded to option page for easy later reference (<=3.4.x)
     if (!get_post_type_object('icit_option_page')) {
         register_post_type('icit_option_page', array('public' => false, 'exclude_from_search' => true, 'publicly_queryable' => false, 'show_ui' => false, 'show_in_menu' => false, 'has_archive' => false, 'can_export' => false, 'rewrite' => false, 'query_var' => false, 'capability_type' => 'page'));
     }
     // Handle settings errors and notices
     add_action('admin_notices', array($this, '_admin_notices'));
 }
function wds_autolinks_settings()
{
    $name = 'wds_autolinks';
    $title = __('Automatic Links', 'wds');
    $description = __('<p>Sometimes you want to always link certain key words to a page on your blog or even a whole new site all together.</p>
	<p>For example, maybe anytime you write the words \'WordPress news\' you want to automatically create a link to the WordPress news blog, wpmu.org. Without this plugin, you would have to manually create these links each time you write the text in your pages and posts - which can be no fun at all.</p>
	<p>This section lets you set those key words and links. First, choose if you want to automatically link key words in posts, pages, or any custom post types you might be using. Usually when you are using automatic links, you will want to check all of the options here.</p>', 'wds');
    $fields = array();
    foreach (get_post_types() as $post_type) {
        if (!in_array($post_type, array('revision', 'nav_menu_item', 'attachment'))) {
            $pt = get_post_type_object($post_type);
            $key = strtolower($pt->name);
            $post_types["l{$key}"] = $pt->labels->name;
            $insert["{$key}"] = $pt->labels->name;
        }
    }
    foreach (get_taxonomies() as $taxonomy) {
        if (!in_array($taxonomy, array('nav_menu', 'link_category', 'post_format'))) {
            $tax = get_taxonomy($taxonomy);
            $key = strtolower($tax->labels->name);
            $taxonomies["l{$key}"] = $tax->labels->name;
        }
    }
    $linkto = array_merge($post_types, $taxonomies);
    $insert['comment'] = __('Comments', 'wds');
    $fields['internal'] = array('title' => '', 'intro' => '', 'options' => array(array('type' => 'checkbox', 'name' => 'insert', 'title' => __('Insert links in', 'wds'), 'items' => $insert), array('type' => 'checkbox', 'name' => 'linkto', 'title' => __('Link to', 'wds'), 'items' => $linkto), array('type' => 'dropdown', 'name' => 'cpt_char_limit', 'title' => __('Minimum post title length', 'wds'), 'description' => __('This is the minimum number of characters your post title has to have to be considered for insertion as auto-link.', 'wds'), 'items' => array_combine(array_merge(array(0), range(1, 25)), array_merge(array(__('Default', 'wds')), range(1, 25)))), array('type' => 'dropdown', 'name' => 'tax_char_limit', 'title' => __('Minimum taxonomy title length', 'wds'), 'description' => __('This is the minimum number of characters your taxonomy title has to have to be considered for insertion as auto-link.', 'wds'), 'items' => array_combine(array_merge(array(0), range(1, 25)), array_merge(array(__('Default', 'wds')), range(1, 25)))), array('type' => 'checkbox', 'name' => 'allow_empty_tax', 'title' => __('Empty taxonomies', 'wds'), 'items' => array('allow_empty_tax' => __('Allow autolinks to empty taxonomies', 'wds'))), array('type' => 'checkbox', 'name' => 'excludeheading', 'title' => __('Exclude Headings', 'wds'), 'items' => array('excludeheading' => __('Prevent linking in heading tags', 'wds'))), array('type' => 'text', 'name' => 'ignorepost', 'title' => __('Ignore posts and pages', 'wds'), 'description' => __('Paste in the IDs, slugs or titles for the post/pages you wish to exclude and separate them by commas', 'wds')), array('type' => 'text', 'name' => 'ignore', 'title' => __('Ignore keywords', 'wds'), 'description' => __('Paste in the keywords you wish to exclude and separate them by commas', 'wds')), array('type' => 'dropdown', 'name' => 'link_limit', 'title' => __('Maximum autolinks number limit', 'wds'), 'description' => __('This is the maximum number of autolinks that will be added to your posts.', 'wds'), 'items' => array_combine(array_merge(array(0), range(1, 20)), array_merge(array(__('Unlimited', 'wds')), range(1, 20)))), array('type' => 'dropdown', 'name' => 'single_link_limit', 'title' => __('Maximum single autolink occurrence', 'wds'), 'description' => __('This is a number of single link replacement occurrences.', 'wds'), 'items' => array_combine(array_merge(array(0), range(1, 10)), array_merge(array(__('Unlimited', 'wds')), range(1, 10)))), array('type' => 'textarea', 'name' => 'customkey', 'title' => __('Custom Keywords', 'wds'), 'description' => __('Paste in the extra keywords you want to automaticaly link. Use comma to seperate keywords and add target url at the end. Use a new line for new url and set of keywords.
				<br />Example:<br />
				<code>WPMU DEV, plugins, themes, http://premium.wpmudev.org/<br />
				WordPress News, http://wpmu.org/<br /></code>', 'wds')), array('type' => 'checkbox', 'name' => 'reduceload', 'title' => __('Other settings', 'wds'), 'items' => array('onlysingle' => __('Process only single posts and pages', 'wds'), 'allowfeed' => __('Process RSS feeds', 'wds'), 'casesens' => __('Case sensitive matching', 'wds'), 'customkey_preventduplicatelink' => __('Prevent duplicate links', 'wds'), 'target_blank' => __('Open links in new tab/window', 'wds'), 'rel_nofollow' => __('Autolinks <code>nofollow</code>', 'wds')))));
    $contextual_help = '';
    if (wds_is_wizard_step('5')) {
        $settings = new WDS_Core_Admin_Tab($name, $title, $description, $fields, 'wds', $contextual_help);
    }
}
Example #26
0
 /**
  * Normalize parameters for field
  *
  * @param array $field
  *
  * @return array
  */
 static function normalize_field($field)
 {
     $field = wp_parse_args($field, array('post_type' => 'post', 'field_type' => 'select_advanced', 'parent' => false, 'query_args' => array()));
     /**
      * Set default placeholder
      * - If multiple post types: show 'Select a post'
      * - If single post type: show 'Select a %post_type_name%'
      */
     if (empty($field['placeholder'])) {
         $label = __('Select a post', 'meta-box');
         if (is_string($field['post_type']) && post_type_exists($field['post_type'])) {
             $post_type_object = get_post_type_object($field['post_type']);
             $label = sprintf(__('Select a %s', 'meta-box'), $post_type_object->labels->singular_name);
         }
         $field['placeholder'] = $label;
     }
     if ($field['parent']) {
         $field['multiple'] = false;
         $field['field_name'] = 'parent_id';
     }
     $field['query_args'] = wp_parse_args($field['query_args'], array('post_type' => $field['post_type'], 'post_status' => 'publish', 'posts_per_page' => -1));
     switch ($field['field_type']) {
         case 'select':
             return RWMB_Select_Field::normalize_field($field);
             break;
         case 'select_advanced':
         default:
             return RWMB_Select_Advanced_Field::normalize_field($field);
     }
 }
Example #27
0
 function map_meta_cap($caps, $cap, $user_id, $args)
 {
     /* If editing, deleting, or reading a review, get the post and post type object. */
     if ('edit_review' == $cap || 'delete_review' == $cap || 'read_review' == $cap) {
         $post = get_post($args[0]);
         $post_type = get_post_type_object($post->post_type);
         /* Set an empty array for the caps. */
         $caps = array();
     }
     /* If editing a review, assign the required capability. */
     if ('edit_review' == $cap) {
         if ($user_id == $post->post_author) {
             $caps[] = $post_type->cap->edit_posts;
         } else {
             $caps[] = $post_type->cap->edit_others_posts;
         }
     } elseif ('delete_review' == $cap) {
         if ($user_id == $post->post_author) {
             $caps[] = $post_type->cap->delete_posts;
         } else {
             $caps[] = $post_type->cap->delete_others_posts;
         }
     } elseif ('read_review' == $cap) {
         if ('private' != $post->post_status) {
             $caps[] = 'read';
         } else {
             $caps[] = $post_type->cap->read_private_posts;
         }
     }
     /* Return the capabilities required by the user. */
     return $caps;
 }
 /**
  * Filters WooCommerce query for translated shop page
  * 
  */
 function shop_page_query($q)
 {
     if (!$q->is_main_query()) {
         return;
     }
     if (!empty($this->shop_page) && $q->get('page_id') !== $this->front_page_id && $this->shop_page_id == $q->get('page_id')) {
         $q->set('post_type', 'product');
         $q->set('page_id', '');
         if (isset($q->query['paged'])) {
             $q->set('paged', $q->query['paged']);
         }
         // Get the actual WP page to avoid errors
         // This is hacky but works. Awaiting http://core.trac.wordpress.org/ticket/21096
         global $wp_post_types;
         $q->is_page = true;
         $wp_post_types['product']->ID = $this->shop_page->ID;
         $wp_post_types['product']->post_title = $this->shop_page->post_title;
         $wp_post_types['product']->post_name = $this->shop_page->post_name;
         // Fix conditional functions
         $q->is_singular = false;
         $q->is_post_type_archive = true;
         $q->is_archive = true;
         $q->queried_object = get_post_type_object('product');
     }
 }
 public function test_postpage_should_be_viewable()
 {
     $post = get_post_type_object('post');
     $this->assertTrue(is_post_type_viewable($post));
     $page = get_post_type_object('page');
     $this->assertTrue(is_post_type_viewable($page));
 }
 function convert_post_edit_caps($rs_reqd_caps, $post_type)
 {
     global $revisionary, $scoper;
     if (!empty($revisionary->skip_revision_allowance) || !rvy_get_option('pending_revisions')) {
         return $rs_reqd_caps;
     }
     $post_id = $scoper->data_sources->detect('id', 'post');
     // don't need to fudge the capreq for post.php unless existing post has public/private status
     $status = get_post_field('post_status', $post_id, 'post');
     $status_obj = get_post_status_object($status);
     if (empty($status_obj->public) && empty($status_obj->private) && 'future' != $status) {
         return $rs_reqd_caps;
     }
     if ($type_obj = get_post_type_object($post_type)) {
         $replace_caps = array('edit_published_posts', 'edit_private_posts', 'publish_posts', $type_obj->cap->edit_published_posts, $type_obj->cap->edit_private_posts, $type_obj->cap->publish_posts);
         $use_cap_req = $type_obj->cap->edit_posts;
     } else {
         $replace_caps = array();
     }
     if (array_intersect($rs_reqd_caps, $replace_caps)) {
         foreach ($rs_reqd_caps as $key => $cap_name) {
             if (in_array($cap_name, $replace_caps)) {
                 $rs_reqd_caps[$key] = $use_cap_req;
             }
         }
     }
     return $rs_reqd_caps;
 }