function wp_edit()
 {
     global $post_type, $wp_query;
     if ($post_type != GALLERY_POST_TYPE_SLUG) {
         return;
     }
     if (!current_user_can('edit_others_pages') || !post_type_supports($post_type, 'page-attributes') && !is_post_type_hierarchical($post_type)) {
         // check permission
         return;
     }
     add_action('restrict_manage_posts', array($this, 'restrict_manage_posts'));
     // posts per page drop down UI
     if (isset($_GET['per_page']) && ($_GET['per_page'] == 99999 || $_GET['per_page'] % 10 == 0)) {
         update_user_option(get_current_user_id(), 'edit_' . $post_type . '_per_page', (int) $_GET['per_page']);
     }
     add_filter('views_' . get_current_screen()->id, array($this, 'sort_by_order_link'));
     // add view by menu order to views
     add_filter('contextual_help', array($this, 'contextual_help'));
     // add contextual help to hierarchical post screens
     #if ( $wp_query->query['orderby'] == 'menu_order title' ) {	// we can only sort if we're organized by menu order; WP 3.2 and 3.1 versions
     wp_enqueue_script('simple-page-ordering', THEMEURL . 'inc/gallery-ordering/simple-page-ordering.js', array('jquery-ui-sortable'), '0.9.7', true);
     $js_trans = array('RepositionTree' => __("Items can only be repositioned within their current branch in the page tree / hierarchy (next to pages with the same parent).\n\nIf you want to move this item into a different part of the page tree, use the Quick Edit feature to change the parent before continuing.", TD));
     #wp_localize_script( 'simple-page-ordering', 'simple_page_ordering_l10n', $js_trans );
     #}
 }
/**
 * Plugin Name: Site Breadcrumbs
 * Plugin URI: https://wordpress.com
 * Description: Quickly add breadcrumbs to the single view of a hierarchical post type or a hierarchical taxonomy.
 * Author: Automattic
 * Version: 1.0
 * Author URI: https://wordpress.com
 * License: GPL2 or later
 */
function jetpack_breadcrumbs()
{
    $taxonomy = is_category() ? 'category' : get_query_var('taxonomy');
    $is_taxonomy_hierarchical = is_taxonomy_hierarchical($taxonomy);
    $post_type = is_page() ? 'page' : get_query_var('post_type');
    $is_post_type_hierarchical = is_post_type_hierarchical($post_type);
    if (!($is_post_type_hierarchical || $is_taxonomy_hierarchical) || is_front_page()) {
        return;
    }
    $breadcrumb = '';
    if ($is_post_type_hierarchical) {
        $post_id = get_queried_object_id();
        $ancestors = array_reverse(get_post_ancestors($post_id));
        if ($ancestors) {
            foreach ($ancestors as $ancestor) {
                $breadcrumb .= '<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="' . esc_url(get_permalink($ancestor)) . '" itemprop="item"><span itemprop="name">' . esc_html(get_the_title($ancestor)) . '</span></a></span>';
            }
        }
        $breadcrumb .= '<span class="current-page" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><span itemprop="name">' . esc_html(get_the_title($post_id)) . '</span></span>';
    } elseif ($is_taxonomy_hierarchical) {
        $current = get_term(get_queried_object_id(), $taxonomy);
        if (is_wp_error($current)) {
            return;
        }
        if ($current->parent) {
            $breadcrumb = jetpack_get_term_parents($current->parent, $taxonomy);
        }
        $breadcrumb .= '<span class="current-category" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><span itemprop="name">' . esc_html($current->name) . '</span></span>';
    }
    $home = '<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="' . esc_url(home_url('/')) . '" class="home-link" itemprop="item" rel="home"><span itemprop="name">' . esc_html__('Home', 'jetpack') . '</span></a></span>';
    echo '<nav class="entry-breadcrumbs" itemscope itemtype="https://schema.org/BreadcrumbList">' . $home . $breadcrumb . '</nav>';
}
 function acs_scripts()
 {
     global $pagenow;
     if (isset($_GET['post_type'])) {
         $post_type = $_GET['post_type'];
         if (is_post_type_hierarchical($post_type)) {
             add_filter('admin_body_class', 'acs_admin_body_class');
         }
         function acs_admin_body_class($classes)
         {
             $classes .= ' ' . 'acs-hier';
             return $classes;
         }
     }
     if (is_admin() && isset($_GET['post_type']) && $pagenow == 'edit.php') {
         //make sure jquery is loaded
         wp_enqueue_script('jquery');
         //cookie script for saving collapse states
         wp_enqueue_script('jquery-cookie', plugins_url('js/jquery.cookie.js', __FILE__), 'jquery', '1.4.0');
         //main collapse pages script
         wp_enqueue_script('acs-js', plugins_url('js/admin_collapse_subpages.js', __FILE__), false, '2.0');
         //Load Styles
         wp_enqueue_style('acs-css', plugins_url('css/style.css', __FILE__), false, '2.0', 'screen');
         wp_localize_script('acs-js', 'acs_l10n_vars', array('lexpandall' => __('Expand All', 'admin-collapse-subpages'), 'lcollapseall' => __('Collapse All', 'admin-collapse-subpages')));
     }
 }
 /**
  * Create a Duplicate post
  */
 static function copy($post, $post_title = '', $post_name = '', $post_type = 'sp_report')
 {
     // We don't want to clone revisions
     if ($post->post_type == 'revision') {
         return;
     }
     if ($post->post_type != 'attachment') {
         $status = 'draft';
     }
     $new_post_author = wp_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_password' => $post->post_password, 'post_status' => $post->post_status, 'post_title' => empty($post_title) ? $post->post_title : $post_title, 'post_type' => empty($post_type) ? $post->post_type : $post_type);
     if ($post_name != '') {
         $new_post['post_name'] = $post_name;
     }
     /*
     $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);
     // If you have written a plugin which uses non-WP database tables to save
     // information about a post you can hook this action to dupe that data.
     if ($post->post_type == 'page' || function_exists('is_post_type_hierarchical') && is_post_type_hierarchical($post->post_type)) {
         do_action('sp_duplicate_page', $new_post_id, $post);
     } else {
         do_action('sp_duplicate_post', $new_post_id, $post);
     }
     delete_post_meta($new_post_id, '_sp_original');
     add_post_meta($new_post_id, '_sp_original', $post->ID);
     add_post_meta($new_post_id, '_open_count', 0);
     return $new_post_id;
 }
Exemple #5
0
 public function shortcode_handler($atts, $content = null, $tag = '')
 {
     if (!is_post_type_hierarchical(get_post_type())) {
         return '';
     }
     $ancestors = get_post_ancestors(get_the_ID());
     if (!$ancestors) {
         return '';
     }
     $r = [];
     $ancestors = array_reverse($ancestors);
     foreach ($ancestors as $ancestor) {
         $classes = ['hestia-ancestor', 'hestia-wrap', sprintf('post-%s', esc_attr($ancestor))];
         $permalink = get_permalink($ancestor);
         $has_thumbnail = has_post_thumbnail($ancestor);
         if ($has_thumbnail) {
             // Because who doesn't love a properly alphabetized list?
             array_unshift($classes, 'has-post-thumbnail');
         }
         $r[] = sprintf('<div class="%s">', implode(' ', $classes));
         $r[] = sprintf('<a href="%1$s">', esc_attr($permalink));
         if ($has_thumbnail) {
             $r[] = get_the_post_thumbnail($ancestor);
         }
         $r[] = get_the_title($ancestor);
         $r[] = '</a>';
         $r[] = '</div>';
     }
     return implode("\n", $r);
 }
Exemple #6
0
 function addMenu()
 {
     global $userdata;
     //put a menu for all custom_type
     $post_types = get_post_types();
     $options = get_option('cpto_options');
     //get the required user capability
     $capability = '';
     if (isset($options['capability']) && !empty($options['capability'])) {
         $capability = $options['capability'];
     } else {
         if (is_numeric($options['level'])) {
             $capability = userdata_get_user_level();
         } else {
             $capability = 'install_plugins';
         }
     }
     foreach ($post_types as $post_type_name) {
         if ($post_type_name == 'page') {
             continue;
         }
         //ignore bbpress
         if ($post_type_name == 'reply' || $post_type_name == 'topic') {
             continue;
         }
         if ($post_type_name == 'post') {
             add_submenu_page('edit.php', __('Re-Order', 'cpt'), __('Re-Order', 'cpt'), $capability, 'order-post-types-' . $post_type_name, array(&$this, 'SortPage'));
         } else {
             if (!is_post_type_hierarchical($post_type_name)) {
                 add_submenu_page('edit.php?post_type=' . $post_type_name, __('Re-Order', 'cpt'), __('Re-Order', 'cpt'), $capability, 'order-post-types-' . $post_type_name, array(&$this, 'SortPage'));
             }
         }
     }
 }
Exemple #7
0
 /**
  * @since 2.2.1
  */
 public function get_original_column_value($column, $id)
 {
     global $post;
     // Setup post data for current post
     $post_old = $post;
     $post = get_post($id);
     setup_postdata($post);
     // Remove Admin Columns action for this column's value
     remove_action("manage_{$this->post_type}_posts_custom_column", array($this, 'manage_value_callback'), 100, 2);
     ob_start();
     // Run WordPress native actions to display column content
     if (is_post_type_hierarchical($this->post_type)) {
         do_action('manage_pages_custom_column', $column, $id);
     } else {
         do_action('manage_posts_custom_column', $column, $id);
     }
     do_action("manage_{$this->post_type}_posts_custom_column", $column, $id);
     $contents = ob_get_clean();
     // Add removed Admin Columns action for this column's value
     add_action("manage_{$this->post_type}_posts_custom_column", array($this, 'manage_value_callback'), 100, 2);
     // Restore original post object
     $post = $post_old;
     if ($post) {
         setup_postdata($post);
     }
     return $contents;
 }
Exemple #8
0
 public function shortcode_handler($atts, $content = null, $tag = '')
 {
     if (!is_post_type_hierarchical(get_post_type())) {
         return '';
     }
     $args = ['order' => 'ASC', 'orderby' => 'menu_order', 'post_parent' => get_the_ID(), 'post_type' => get_post_type(), 'posts_per_page' => 20];
     $query = new WP_Query($args);
     $r = [];
     if ($query->have_posts()) {
         while ($query->have_posts()) {
             $query->the_post();
             $classes = ['hestia-child', 'hestia-wrap', sprintf('post-%s', esc_attr(get_the_ID()))];
             $has_thumbnail = has_post_thumbnail();
             $permalink = get_permalink();
             if ($has_thumbnail) {
                 // Because who doesn't love a properly alphabetized list?
                 array_unshift($classes, 'has-post-thumbnail');
             }
             $r[] = sprintf('<div class="%s">', implode(' ', $classes));
             $r[] = sprintf('<a href="%s">', esc_attr($permalink));
             if ($has_thumbnail) {
                 $r[] = get_the_post_thumbnail();
             }
             $r[] = get_the_title();
             $r[] = '</a>';
             $r[] = '</div>';
         }
     }
     wp_reset_postdata();
     return implode("\n", $r);
 }
Exemple #9
0
 /**
  * put your comment there...
  * 
  */
 protected function isHierarchical()
 {
     // Initialize.
     $typeParams =& $this->getTypeParams();
     // Check if post_type hierarchical.
     return is_post_type_hierarchical($typeParams['type']);
 }
 public static function init()
 {
     global $pagenow;
     if ($pagenow == 'edit.php' && !empty($_REQUEST['post_type']) && $_REQUEST['post_type'] == EM_POST_TYPE_EVENT) {
         //only needed for events list
         if (!empty($_REQUEST['category_id']) && is_numeric($_REQUEST['category_id'])) {
             $term = get_term_by('id', $_REQUEST['category_id'], EM_TAXONOMY_CATEGORY);
             if (!empty($term->slug)) {
                 $_REQUEST['category_id'] = $term->slug;
             }
         }
         //hide some cols by default:
         $screen = 'edit-' . EM_POST_TYPE_EVENT;
         $hidden = get_user_option('manage' . $screen . 'columnshidden');
         if (!$hidden) {
             $hidden = array('event-id');
             update_user_option(get_current_user_id(), "manage{$screen}columnshidden", $hidden, true);
         }
         //deal with actions
         $row_action_type = is_post_type_hierarchical(EM_POST_TYPE_EVENT) ? 'page_row_actions' : 'post_row_actions';
         add_filter($row_action_type, array('EM_Event_Posts_Admin', 'row_actions'), 10, 2);
         add_action('admin_head', array('EM_Event_Posts_Admin', 'admin_head'));
         //collumns
         add_filter('manage_edit-' . EM_POST_TYPE_EVENT . '_columns', array('EM_Event_Posts_Admin', 'columns_add'));
         add_filter('manage_' . EM_POST_TYPE_EVENT . '_posts_custom_column', array('EM_Event_Posts_Admin', 'columns_output'), 10, 2);
     }
     //clean up the views in the admin selection area - WIP
     //add_filter('views_edit-'.EM_POST_TYPE_EVENT, array('EM_Event_Posts_Admin','restrict_views'),10,2);
     //add_filter('views_edit-event-recurring', array('EM_Event_Posts_Admin','restrict_views'),10,2);
     //add filters to event post list tables
     add_action('restrict_manage_posts', array('EM_Event_Posts_Admin', 'restrict_manage_posts'));
 }
 /**
  * Add custom columns hooks.
  */
 public function add_custom_columns_hooks()
 {
     if ($this->has_custom_columns()) {
         $post_type = isset($_REQUEST['post_type']) ? $_REQUEST['post_type'] : 'post';
         switch ($post_type) {
             case 'post':
             case 'page':
                 add_filter('manage_' . $post_type . 's_columns', array($this->get_custom_column_instance(), 'add_posts_management_column'));
                 if ($this->get_custom_column_instance()->show_management_column_content($post_type)) {
                     add_filter('manage_' . $post_type . 's_custom_column', array($this->get_custom_column_instance(), 'add_content_for_posts_management_column'));
                 }
                 break;
             default:
                 if (in_array($post_type, array_keys($this->sitepress->get_translatable_documents()), true)) {
                     add_filter('manage_' . $post_type . '_posts_columns', array($this->get_custom_column_instance(), 'add_posts_management_column'));
                     if (is_post_type_hierarchical($post_type)) {
                         if ($this->get_custom_column_instance()->show_management_column_content($post_type)) {
                             add_action('manage_pages_custom_column', array($this->get_custom_column_instance(), 'add_content_for_posts_management_column'));
                             add_action('manage_posts_custom_column', array($this->get_custom_column_instance(), 'add_content_for_posts_management_column'));
                             // add this too - for more types plugin
                         }
                     } else {
                         if ($this->get_custom_column_instance()->show_management_column_content($post_type)) {
                             add_action('manage_posts_custom_column', array($this->get_custom_column_instance(), 'add_content_for_posts_management_column'));
                         }
                     }
                 }
         }
     }
 }
 function init()
 {
     global $pagenow;
     if ($pagenow == 'edit.php' && !empty($_REQUEST['post_type']) && $_REQUEST['post_type'] == EM_POST_TYPE_EVENT) {
         //only needed for events list
         if (!empty($_REQUEST['category_id']) && is_numeric($_REQUEST['category_id'])) {
             $term = get_term_by('id', $_REQUEST['category_id'], EM_TAXONOMY_CATEGORY);
             if (!empty($term->slug)) {
                 $_REQUEST['category_id'] = $term->slug;
             }
         }
         //hide some cols by default:
         $screen = 'edit-' . EM_POST_TYPE_EVENT;
         $hidden = get_user_option('manage' . $screen . 'columnshidden');
         if (!$hidden) {
             $hidden = array('event-id');
             update_user_option(get_current_user_id(), "manage{$screen}columnshidden", $hidden, true);
         }
         //deal with actions
         $row_action_type = is_post_type_hierarchical(EM_POST_TYPE_EVENT) ? 'page_row_actions' : 'post_row_actions';
         add_filter($row_action_type, array('EM_Event_Posts_Admin', 'row_actions'), 10, 2);
         add_action('admin_head', array('EM_Event_Posts_Admin', 'admin_head'));
         //collumns
         add_filter('manage_edit-' . EM_POST_TYPE_EVENT . '_columns', array('EM_Event_Posts_Admin', 'columns_add'));
         add_filter('manage_' . EM_POST_TYPE_EVENT . '_posts_custom_column', array('EM_Event_Posts_Admin', 'columns_output'), 10, 2);
         //TODO alter views of locations, events and recurrences, specifically find a good way to alter the wp_count_posts method to force user owned posts only
         //add_filter('views_edit-'.EM_POST_TYPE_EVENT, array('EM_Event_Posts_Admin','views'),10,1);
     }
     add_action('restrict_manage_posts', array('EM_Event_Posts_Admin', 'restrict_manage_posts'));
 }
 function wp_unique_post_slug($slug_suggested, $post_id, $post_status, $post_type, $post_parent, $slug)
 {
     if ($post_status !== 'auto-draft' && $this->sitepress->is_translated_post_type($post_type)) {
         $post_language = $post_id ? $this->post_translations->get_element_lang_code($post_id) : $this->sitepress->get_current_language();
         $parent = is_post_type_hierarchical($post_type) ? (int) $post_parent : false;
         $slug_suggested_wpml = $this->find_unique_slug_post($post_id, $post_type, $post_language, $parent, $slug);
     }
     return isset($slug_suggested_wpml) ? $slug_suggested_wpml : $slug_suggested;
 }
 function test_register_post_type()
 {
     $this->assertNull(get_post_type_object('foo'));
     register_post_type('foo');
     $pobj = get_post_type_object('foo');
     $this->assertInstanceOf('WP_Post_Type', $pobj);
     $this->assertEquals('foo', $pobj->name);
     // Test some defaults
     $this->assertFalse(is_post_type_hierarchical('foo'));
     $this->assertEquals(array(), get_object_taxonomies('foo'));
     _unregister_post_type('foo');
 }
function content_audit_column_setup()
{
    global $current_user;
    get_currentuserinfo();
    $role = is_array($current_user->roles) ? array_shift($current_user->roles) : '';
    $options = get_option('content_audit');
    if (!is_array($options['post_types'])) {
        $options['post_types'] = array($options['post_types']);
    }
    $allowed = $options['rolenames'];
    if (!is_array($allowed)) {
        $allowed = array($allowed);
    }
    if (is_multisite() && is_super_admin() || in_array($role, $allowed)) {
        foreach ($options['post_types'] as $type) {
            switch ($type) {
                case 'post':
                    add_filter('manage_posts_columns', 'content_audit_columns');
                    add_action('manage_posts_custom_column', 'content_audit_custom_column', 10, 2);
                    add_filter('manage_edit-post_sortable_columns', 'content_audit_register_sortable');
                    break;
                case 'page':
                    add_filter('manage_pages_columns', 'content_audit_columns');
                    add_action('manage_pages_custom_column', 'content_audit_custom_column', 10, 2);
                    add_filter('manage_edit-page_sortable_columns', 'content_audit_register_sortable');
                    break;
                case 'attachment':
                    add_filter('manage_media_columns', 'content_audit_columns');
                    add_action('manage_media_custom_column', 'content_audit_custom_column', 10, 2);
                    add_filter('manage_edit-media_sortable_columns', 'content_audit_register_sortable');
                    break;
                default:
                    if (post_type_exists($type) && in_array($type, $options['post_types'])) {
                        add_filter('manage_' . $type . '_posts_columns', 'content_audit_columns');
                        add_filter('manage_edit-' . $type . '_sortable_columns', 'content_audit_register_sortable');
                        if (is_post_type_hierarchical($type) == true) {
                            add_action('manage_pages_custom_column', 'content_audit_custom_column', 10, 2);
                        } else {
                            add_action('manage_posts_custom_column', 'content_audit_custom_column', 10, 2);
                        }
                    }
            }
            // add filter dropdowns
            add_action('restrict_manage_posts', 'content_audit_restrict_content_authors');
            add_action('restrict_manage_posts', 'content_audit_restrict_content_owners');
            add_action('restrict_manage_posts', 'content_audit_restrict_content_status');
            // modify edit screens' query when dropdown option is chosen
            add_filter('posts_where', 'content_audit_posts_where');
            // Add author field to quick edit
            //			add_action( 'quick_edit_custom_box', 'add_quickedit_content_owner' );
        }
    }
}
 /**
  * rebuild permalink when saving post if parent/name has changed
  * Hook for 'post_updated'
  */
 public function update_post($post_ID, $post_after, $post_before)
 {
     global $sublanguage_admin;
     // only if post is hierarchical and translatable or translation
     if (in_array($post_after->post_type, $sublanguage_admin->options['cpt']) && is_post_type_hierarchical($post_after->post_type) || $sublanguage_admin->get_language_by_type($post_after->post_type) !== false) {
         // only if parent or name have changed
         if ($post_after->post_parent != $post_before->post_parent || $post_after->post_name != $post_before->post_name || $post_after->post_status != $post_before->post_status) {
             $sublanguage_admin->disable_translate_home_url = true;
             flush_rewrite_rules();
             $sublanguage_admin->disable_translate_home_url = false;
         }
     }
 }
 /**
  * Post Items
  */
 public function addPostVars($post)
 {
     $this->post_data->id = $post->ID;
     $this->post_data->parent_id = $post->post_parent;
     $this->post_data->title = $post->post_title;
     $this->post_data->password = $post->post_password;
     $this->post_data->status = $post->post_status;
     $this->post_data->type = $post->post_type;
     $this->post_data->comment_status = $post->comment_status;
     $this->post_data->content = $post->post_content;
     $this->post_data->hierarchical = is_post_type_hierarchical($post->post_type);
     $this->post_data->link = get_the_permalink($post->ID);
 }
Exemple #18
0
 function isParentOf($query)
 {
     $this->setupBaseInfo();
     if (!is_post_type_hierarchical($this->type)) {
         return false;
     }
     if (!isset($query->post) || !isset($query->post->post_type) || $this->type != $query->post->post_type) {
         return false;
     }
     $depth = 0;
     $found = $this->findChild($this->id, $query->post->ID, $this->children, $depth);
     return $found;
 }
 public function can_monitor_post($post, $post_before, $form_data)
 {
     if ($post->post_status !== 'publish' || $post_before->post_status !== 'publish') {
         return false;
     }
     if (is_post_type_hierarchical($post->post_type)) {
         return false;
     }
     if (!isset($form_data['redirection_slug'])) {
         return false;
     }
     return true;
 }
Exemple #20
0
 /**
  * @covers ::bbp_topic_post_type
  * @covers ::bbp_get_topic_post_type
  */
 public function test_bbp_topic_post_type()
 {
     $t = $this->factory->topic->create();
     $tobj = get_post_type_object('topic');
     $this->assertInstanceOf('stdClass', $tobj);
     $this->assertEquals('topic', $tobj->name);
     // Test some defaults
     $this->assertFalse(is_post_type_hierarchical('topic'));
     $topic_type = bbp_topic_post_type($t);
     $this->expectOutputString('topic', $topic_type);
     $topic_type = bbp_get_topic_post_type($t);
     $this->assertSame('topic', $topic_type);
 }
Exemple #21
0
 /**
  * @covers ::bbp_reply_post_type
  * @covers ::bbp_get_reply_post_type
  */
 public function test_bbp_reply_post_type()
 {
     $t = $this->factory->topic->create();
     $r = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('topic_id' => $t)));
     $robj = get_post_type_object('reply');
     $this->assertInstanceOf('stdClass', $robj);
     $this->assertEquals('reply', $robj->name);
     // Test some defaults
     $this->assertFalse(is_post_type_hierarchical('topic'));
     $reply_type = bbp_reply_post_type($r);
     $this->expectOutputString('reply', $reply_type);
     $reply_type = bbp_get_reply_post_type($r);
     $this->assertSame('reply', $reply_type);
 }
Exemple #22
0
 public static function act_save_item($item_source, $post_id, $post)
 {
     if (!empty($_REQUEST['action']) && 'untrash' == $_REQUEST['action']) {
         return;
     }
     // WP always passes post object into do_action('save_post')
     if (!is_object($post)) {
         if (!($post = get_post($post_id))) {
             return;
         }
     }
     // operations in this function do not apply to revision save
     if ('revision' == $post->post_type) {
         return;
     }
     if (!in_array($post->post_type, pp_get_enabled_post_types())) {
         if (!empty($_REQUEST['pp_enable_post_type'])) {
             $enabled = get_option('pp_enabled_post_types');
             $enabled[$post->post_type] = '1';
             update_option('pp_enabled_post_types', $enabled);
         }
         return;
     }
     // don't execute this action handler more than one per post save
     static $saved_items;
     if (!isset($saved_items)) {
         $saved_items = array();
     }
     if (isset($saved_items[$post_id])) {
         return;
     }
     $saved_items[$post_id] = 1;
     $is_new = self::is_new_post($post_id, $post);
     if (is_post_type_hierarchical($post->post_type)) {
         $parent_info = self::get_post_parent_info($post_id, $post, true);
         extract($parent_info, EXTR_SKIP);
         // $set_parent, $last_parent
         if (is_numeric($last_parent)) {
             // not theoretically necessary, but an easy safeguard to avoid re-inheriting parent roles
             $is_new = false;
         }
     }
     if (empty($_REQUEST['page']) || 'rvy-revisions' != $_REQUEST['page']) {
         usleep(5000);
         // Work around intermittent failure to propagate exceptions.  Maybe storage of post row is delayed on some db servers.
         require_once dirname(__FILE__) . '/item-save_pp.php';
         PP_ItemSave::item_update_process_exceptions('post', 'post', $post_id, compact('is_new', 'set_parent', 'last_parent', 'disallow_manual_entry', 'via_item_type'));
     }
 }
 public function post_updated($post_id, $post, $post_before)
 {
     if ($post->post_status !== 'publish' || is_post_type_hierarchical($post->post_type)) {
         return;
     }
     if (isset($_POST['redirection_slug'])) {
         $after = parse_url(get_permalink($post_id));
         $after = $after['path'];
         $before = esc_url($_POST['redirection_slug']);
         $site = parse_url(get_site_url());
         if (in_array($post->post_status, array('publish', 'static')) && $before !== $after && $before !== '/' && (!isset($site['path']) || isset($site['path']) && $before !== $site['path'] . '/')) {
             Red_Item::create(array('source' => $before, 'target' => $after, 'match' => 'url', 'red_action' => 'url', 'group_id' => $this->monitor_group_id));
         }
     }
 }
 public function load_edit_screen()
 {
     if (!current_user_can('edit_others_pages')) {
         return;
     }
     $screen = get_current_screen();
     $sortable = post_type_supports($screen->post_type, 'page-attributes') || is_post_type_hierarchical($screen->post_type);
     // check permission
     $sortable = apply_filters('simple_page_ordering_is_sortable', $sortable, $screen->post_type);
     if (!$sortable) {
         return;
     }
     add_filter('views_' . $screen->id, array($this, 'sort_by_order_link'));
     // add view by menu order to views
     add_action('wp', array($this, 'wp'));
     add_action('admin_head', array($this, 'admin_head'));
 }
 /**
  * Perfomr duplicating post/page
  * @param object $post
  * @param string $status
  * @param string $parent_id
  * @return int
  */
 function duplicate($post, $status = '', $parent_id = '')
 {
     $prefix = '';
     $suffix = '';
     $this->old_post_content = $post->post_content;
     $this->new_post_content = tf_generate_new_shortcode_ids($post->post_content);
     // We don't want to clone revisions
     if ($post->post_type == 'revision') {
         return;
     }
     if ($post->post_type != 'attachment') {
         $prefix = '';
         //$suffix = ' Copy';
         $suffix = '';
     }
     $new_post_author = $this->duplicate_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' => $this->new_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' => $new_post_status = empty($status) ? $post->post_status : $status, 'post_title' => $prefix . $post->post_title . $suffix, 'post_type' => $post->post_type);
     $new_post_id = wp_insert_post($new_post);
     // apply hook to duplicate action
     if ($post->post_type == 'page' || function_exists('is_post_type_hierarchical') && is_post_type_hierarchical($post->post_type)) {
         do_action('tf_duplicate_page', $new_post_id, $post);
     } else {
         do_action('tf_duplicate_post', $new_post_id, $post);
     }
     // If the copy is published or scheduled, we have to set a proper slug.
     if ($new_post_status == 'publish' || $new_post_status == 'future') {
         $post_name = wp_unique_post_slug($post->post_name, $new_post_id, $new_post_status, $post->post_type, $new_post_parent);
         $new_post = array();
         $new_post['ID'] = $new_post_id;
         $new_post['post_name'] = $post_name;
         // Update the post into the database
         wp_update_post($new_post);
     }
     // set new url
     if ($post->post_type == 'page') {
         $this->new_url = get_page_link($new_post_id);
     } else {
         $this->new_url = get_permalink($new_post_id);
     }
     // check if admin
     if ($this->edit_link) {
         $this->new_url = get_edit_post_link($new_post_id);
     }
     return $new_post_id;
 }
Exemple #26
0
 /**
  * Persistent Post list mode
  * 
  * @author http://wordpress.stackexchange.com/a/47417/12615
  * @return type
  */
 public function persistent_posts_list_mode()
 {
     global $typenow;
     if (is_post_type_hierarchical($typenow)) {
         return;
     }
     // don't care
     if (isset($_REQUEST['mode'])) {
         // save the list mode
         update_user_meta(get_current_user_id(), 'posts_list_mode' . $typenow, $_REQUEST['mode']);
         return;
     }
     // retrieve the list mode
     $mode = get_user_meta(get_current_user_id(), 'posts_list_mode' . $typenow, true);
     if ($mode) {
         $_REQUEST['mode'] = $mode;
     }
 }
 /**
  * @covers ::bbp_forum_post_type
  * @covers ::bbp_get_forum_post_type
  */
 public function test_bbp_get_forum_post_type()
 {
     $f = $this->factory->forum->create();
     $fobj = get_post_type_object('forum');
     // WordPress 4.6 introduced `WP_Post_Type` class
     if (bbp_get_major_wp_version() < 4.6) {
         $this->assertInstanceOf('stdClass', $fobj);
     } else {
         $this->assertInstanceOf('WP_Post_Type', $fobj);
     }
     $this->assertEquals('forum', $fobj->name);
     // Test some defaults
     $this->assertTrue(is_post_type_hierarchical('forum'));
     $forum_type = bbp_forum_post_type($f);
     $this->expectOutputString('forum', $forum_type);
     $forum_type = bbp_get_forum_post_type($f);
     $this->assertSame('forum', $forum_type);
 }
Exemple #28
0
 function addMenu()
 {
     global $userdata;
     //put a menu for all custom_type
     $post_types = get_post_types();
     $options = cpt_get_options();
     //get the required user capability
     $capability = '';
     if (isset($options['capability']) && !empty($options['capability'])) {
         $capability = $options['capability'];
     } else {
         if (is_numeric($options['level'])) {
             $capability = userdata_get_user_level();
         } else {
             $capability = 'install_plugins';
         }
     }
     foreach ($post_types as $post_type_name) {
         if ($post_type_name == 'page') {
             continue;
         }
         //ignore bbpress
         if ($post_type_name == 'reply' || $post_type_name == 'topic') {
             continue;
         }
         if (is_post_type_hierarchical($post_type_name)) {
             continue;
         }
         $post_type_data = get_post_type_object($post_type_name);
         if ($post_type_data->show_ui === FALSE) {
             continue;
         }
         if (isset($options['show_reorder_interfaces'][$post_type_name]) && $options['show_reorder_interfaces'][$post_type_name] != 'show') {
             continue;
         }
         if ($post_type_name == 'post') {
             add_submenu_page('edit.php', __('Re-Order', 'cpt'), __('Re-Order', 'cpt'), $capability, 'order-post-types-' . $post_type_name, array(&$this, 'SortPage'));
         } elseif ($post_type_name == 'attachment') {
             add_submenu_page('upload.php', __('Re-Order', 'cpt'), __('Re-Order', 'cpt'), $capability, 'order-post-types-' . $post_type_name, array(&$this, 'SortPage'));
         } else {
             add_submenu_page('edit.php?post_type=' . $post_type_name, __('Re-Order', 'cpt'), __('Re-Order', 'cpt'), $capability, 'order-post-types-' . $post_type_name, array(&$this, 'SortPage'));
         }
     }
 }
 /**
  * Load up page ordering scripts for the edit screen
  */
 public static function load_edit_screen()
 {
     $screen = get_current_screen();
     $post_type = $screen->post_type;
     // is post type sortable?
     $sortable = post_type_supports($post_type, 'page-attributes') || is_post_type_hierarchical($post_type);
     // check permission
     if (!($sortable = apply_filters('simple_page_ordering_is_sortable', $sortable, $post_type))) {
         return;
     }
     // does user have the right to manage these post objects?
     if (!self::check_edit_others_caps($post_type)) {
         return;
     }
     add_filter('views_' . $screen->id, array(__CLASS__, 'sort_by_order_link'));
     // add view by menu order to views
     add_action('wp', array(__CLASS__, 'wp'));
     add_action('admin_head', array(__CLASS__, 'admin_head'));
 }
 public function load_edit_screen()
 {
     $screen = get_current_screen();
     $post_type = $screen->post_type;
     // is post type sortable?
     $sortable = post_type_supports($post_type, 'page-attributes') || is_post_type_hierarchical($post_type);
     // check permission
     if (!($sortable = apply_filters('simple_page_ordering_is_sortable', $sortable, $post_type))) {
         return;
     }
     // does user have the right to manage these post objects?
     if (!$this->check_edit_others_caps($post_type)) {
         return;
     }
     add_filter('views_' . $screen->id, array($this, 'sort_by_order_link'));
     // add view by menu order to views
     wp_enqueue_script('simple-page-ordering', get_bloginfo('template_url') . '/lib/admin/ordering/ordering.dev.js', array('jquery-ui-sortable'), '2.1', true);
     wp_enqueue_style('ordering-css', get_bloginfo('template_url') . '/lib/admin/ordering/ordering.css');
 }