Ejemplo n.º 1
0
 /**
  * Test autosaving a locked post
  * @return void
  */
 public function test_autosave_locked_post()
 {
     // Lock the post to another user
     wp_set_current_user(self::$editor_id);
     wp_set_post_lock(self::$post_id);
     wp_set_current_user(self::$admin_id);
     // Ensure post is locked
     $this->assertEquals(self::$editor_id, wp_check_post_lock(self::$post_id));
     // Set up the $_POST request
     $md5 = md5(uniqid());
     $_POST = array('action' => 'heartbeat', '_nonce' => wp_create_nonce('heartbeat-nonce'), 'data' => array('wp_autosave' => array('post_id' => self::$post_id, '_wpnonce' => wp_create_nonce('update-post_' . self::$post_id), 'post_content' => self::$post->post_content . PHP_EOL . $md5, 'post_type' => 'post')));
     // Make the request
     try {
         $this->_handleAjax('heartbeat');
     } catch (WPAjaxDieContinueException $e) {
         unset($e);
     }
     $response = json_decode($this->_last_response, true);
     // Ensure everything is correct
     $this->assertNotEmpty($response['wp_autosave']);
     $this->assertTrue($response['wp_autosave']['success']);
     // Check that the original post was NOT edited
     $post = get_post(self::$post_id);
     $this->assertFalse(strpos($post->post_content, $md5));
     // Check if the autosave post was created
     $autosave = wp_get_post_autosave(self::$post_id, get_current_user_id());
     $this->assertNotEmpty($autosave);
     $this->assertGreaterThanOrEqual(0, strpos($autosave->post_content, $md5));
 }
Ejemplo n.º 2
0
 protected function handle_locking($post_id)
 {
     $last_user = wp_check_post_lock($post_id);
     if ($last_user) {
         $message = __('Error: %s is currently editing this.', 'front-end-editor');
         $message = sprintf($message, esc_html(get_userdata($last_user)->display_name));
         throw new Exception($message);
     }
     wp_set_post_lock($post_id);
 }
Ejemplo n.º 3
0
 public function test_postLock()
 {
     $this->user_own_post = $this->factory->user->create(['role' => 'administrator']);
     $this->user_editor = $this->factory->user->create(['role' => 'administrator']);
     wp_set_current_user($this->user_own_post);
     $post = $this->factory->post->create_and_get();
     $data = ['elementor_post_lock' => ['post_ID' => $post->ID]];
     $response = apply_filters('heartbeat_received', [], $data, '');
     // Switch to other user
     wp_set_current_user($this->user_editor);
     $this->assertEquals($this->user_own_post, wp_check_post_lock($post->ID));
     $response = apply_filters('heartbeat_received', [], $data, '');
     $this->assertArrayHasKey('locked_user', $response);
 }
Ejemplo n.º 4
0
 /**
  * Initializes the builder interface.
  *
  * @since 1.0
  * @return void
  */
 public static function init()
 {
     // Enable editing if the builder is active.
     if (FLBuilderModel::is_builder_active() && !defined('DOING_AJAX')) {
         // Tell W3TC not to minify while the builder is active.
         define('DONOTMINIFY', true);
         // Tell Autoptimize not to minify while the builder is active.
         add_filter('autoptimize_filter_noptimize', '__return_true');
         // Remove 3rd party editor buttons.
         remove_all_actions('media_buttons', 999999);
         remove_all_actions('media_buttons_context', 999999);
         // Get the post.
         require_once ABSPATH . 'wp-admin/includes/post.php';
         $post_id = FLBuilderModel::get_post_id();
         // Check to see if the post is locked.
         if (wp_check_post_lock($post_id) !== false) {
             header('Location: ' . admin_url('/post.php?post=' . $post_id . '&action=edit'));
         } else {
             FLBuilderModel::enable_editing();
         }
     }
 }
Ejemplo n.º 5
0
 private function edit()
 {
     global $title, $post_ID, $p, $post, $post_referredby;
     $title = __('Edit Page');
     $page_ID = $post_ID = $p = (int) $_GET['post'];
     $post = $this->get_page($post_ID);
     if (current_user_can('edit_page', $page_ID)) {
         if ($last = wp_check_post_lock($post->ID)) {
             $last_user = get_userdata($last);
             $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
             $message = sprintf(__('Warning: %s is currently editing this page'), esc_html($last_user_name));
             $message = '<p><font color="red">' . $message . '</font></p>';
             add_action('admin_notices', create_function('', "echo '{$message}';"));
         } else {
             wp_set_post_lock($post->ID);
         }
     } else {
         $this->base->ks_die(__('You are not allowed to edit this page.'));
         // exit;
     }
     $post_referredby = $this->sendback;
     include dirname(__FILE__) . '/edit-page-form.php';
 }
 function callback($path = '', $blog_id = 0, $post_id = 0)
 {
     $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
     if (is_wp_error($blog_id)) {
         return $blog_id;
     }
     $args = $this->query_args();
     $input = $this->input(false);
     if (!is_array($input) || !$input) {
         return new WP_Error('invalid_input', 'Invalid request input', 400);
     }
     $post = get_post($post_id);
     if (!$post || is_wp_error($post)) {
         return new WP_Error('unknown_post', 'Unknown post', 404);
     }
     if (!current_user_can('edit_post', $post->ID)) {
         return new WP_Error('unauthorized', 'User cannot edit post', 403);
     }
     $post_data = array('post_ID' => $post_id, 'post_title' => $input['title'], 'post_content' => $input['content'], 'post_excerpt' => $input['excerpt']);
     $preview_url = add_query_arg('preview', 'true', get_permalink($post->ID));
     if (!wp_check_post_lock($post->ID) && get_current_user_id() == $post->post_author && ('auto-draft' == $post->post_status || 'draft' == $post->post_status)) {
         // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked
         $auto_ID = edit_post(wp_slash($post_data));
     } else {
         // Non drafts or other users drafts are not overwritten. The autosave is stored in a special post revision for each user.
         $auto_ID = wp_create_post_autosave(wp_slash($post_data));
         $nonce = wp_create_nonce('post_preview_' . $post->ID);
         $preview_url = add_query_arg(array('preview_id' => $auto_ID, 'preview_nonce' => $nonce), $preview_url);
     }
     $updated_post = get_post($auto_ID);
     if ($updated_post && $updated_post->ID && $updated_post->post_modified) {
         return array('ID' => $auto_ID, 'post_ID' => $post->ID, 'modified' => $this->format_date($updated_post->post_modified), 'preview_URL' => $preview_url);
     } else {
         return new WP_Error('autosave_error', __('Autosave encountered an unexpected error', 'jetpack'), 500);
     }
 }
Ejemplo n.º 7
0
     }
     redirect_post($post_id);
     // Send user on their way while we keep working
     exit;
 case 'trash':
     check_admin_referer('trash-post_' . $post_id);
     if (!$post) {
         wp_die(__('The item you are trying to move to the Trash no longer exists.'));
     }
     if (!$post_type_object) {
         wp_die(__('Unknown post type.'));
     }
     if (!current_user_can('delete_post', $post_id)) {
         wp_die(__('You are not allowed to move this item to the Trash.'));
     }
     if ($user_id = wp_check_post_lock($post_id)) {
         $user = get_userdata($user_id);
         wp_die(sprintf(__('You cannot move this item to the Trash. %s is currently editing.'), $user->display_name));
     }
     if (!wp_trash_post($post_id)) {
         wp_die(__('Error in moving to Trash.'));
     }
     wp_redirect(add_query_arg(array('trashed' => 1, 'ids' => $post_id), $sendback));
     exit;
 case 'untrash':
     check_admin_referer('untrash-post_' . $post_id);
     if (!$post) {
         wp_die(__('The item you are trying to restore from the Trash no longer exists.'));
     }
     if (!$post_type_object) {
         wp_die(__('Unknown post type.'));
Ejemplo n.º 8
0
/**
 * Process the post data for the bulk editing of posts.
 *
 * Updates all bulk edited posts/pages, adding (but not removing) tags and
 * categories. Skips pages when they would be their own parent or child.
 *
 * @since 2.7.0
 *
 * @param array $post_data Optional, the array of post data to process if not provided will use $_POST superglobal.
 * @return array
 */
function bulk_edit_posts($post_data = null)
{
    global $wpdb;
    if (empty($post_data)) {
        $post_data =& $_POST;
    }
    if (isset($post_data['post_type'])) {
        $ptype = get_post_type_object($post_data['post_type']);
    } else {
        $ptype = get_post_type_object('post');
    }
    if (!current_user_can($ptype->cap->edit_posts)) {
        if ('page' == $ptype->name) {
            wp_die(__('You are not allowed to edit pages.'));
        } else {
            wp_die(__('You are not allowed to edit posts.'));
        }
    }
    if (-1 == $post_data['_status']) {
        $post_data['post_status'] = null;
        unset($post_data['post_status']);
    } else {
        $post_data['post_status'] = $post_data['_status'];
    }
    unset($post_data['_status']);
    $post_IDs = array_map('intval', (array) $post_data['post']);
    $reset = array('post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tax_input', 'post_category', 'sticky');
    foreach ($reset as $field) {
        if (isset($post_data[$field]) && ('' == $post_data[$field] || -1 == $post_data[$field])) {
            unset($post_data[$field]);
        }
    }
    if (isset($post_data['post_category'])) {
        if (is_array($post_data['post_category']) && !empty($post_data['post_category'])) {
            $new_cats = array_map('absint', $post_data['post_category']);
        } else {
            unset($post_data['post_category']);
        }
    }
    $tax_input = array();
    if (isset($post_data['tax_input'])) {
        foreach ($post_data['tax_input'] as $tax_name => $terms) {
            if (empty($terms)) {
                continue;
            }
            if (is_taxonomy_hierarchical($tax_name)) {
                $tax_input[$tax_name] = array_map('absint', $terms);
            } else {
                $comma = _x(',', 'tag delimiter');
                if (',' !== $comma) {
                    $terms = str_replace($comma, ',', $terms);
                }
                $tax_input[$tax_name] = explode(',', trim($terms, " \n\t\r\v,"));
            }
        }
    }
    if (isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent'])) {
        $pages = $wpdb->get_results("SELECT ID, post_parent FROM {$wpdb->posts} WHERE post_type = 'page'");
        $children = array();
        for ($i = 0; $i < 50 && $parent > 0; $i++) {
            $children[] = $parent;
            foreach ($pages as $page) {
                if ($page->ID == $parent) {
                    $parent = $page->post_parent;
                    break;
                }
            }
        }
    }
    if (isset($post_data['post_format'])) {
        if ('0' == $post_data['post_format']) {
            $post_data['post_format'] = false;
        } elseif (!current_theme_supports('post-formats', $post_data['post_format'])) {
            unset($post_data['post_format']);
        }
    }
    $updated = $skipped = $locked = array();
    foreach ($post_IDs as $post_ID) {
        $post_type_object = get_post_type_object(get_post_type($post_ID));
        if (!isset($post_type_object) || isset($children) && in_array($post_ID, $children) || !current_user_can($post_type_object->cap->edit_post, $post_ID)) {
            $skipped[] = $post_ID;
            continue;
        }
        if (wp_check_post_lock($post_ID)) {
            $locked[] = $post_ID;
            continue;
        }
        $post = get_post($post_ID);
        $tax_names = get_object_taxonomies($post);
        foreach ($tax_names as $tax_name) {
            $taxonomy_obj = get_taxonomy($tax_name);
            if (isset($tax_input[$tax_name]) && current_user_can($taxonomy_obj->cap->assign_terms)) {
                $new_terms = $tax_input[$tax_name];
            } else {
                $new_terms = array();
            }
            if ($taxonomy_obj->hierarchical) {
                $current_terms = (array) wp_get_object_terms($post_ID, $tax_name, array('fields' => 'ids'));
            } else {
                $current_terms = (array) wp_get_object_terms($post_ID, $tax_name, array('fields' => 'names'));
            }
            $post_data['tax_input'][$tax_name] = array_merge($current_terms, $new_terms);
        }
        if (isset($new_cats) && in_array('category', $tax_names)) {
            $cats = (array) wp_get_post_categories($post_ID);
            $post_data['post_category'] = array_unique(array_merge($cats, $new_cats));
            unset($post_data['tax_input']['category']);
        }
        $post_data['post_mime_type'] = $post->post_mime_type;
        $post_data['guid'] = $post->guid;
        $post_data['ID'] = $post_ID;
        $updated[] = wp_update_post($post_data);
        if (isset($post_data['sticky']) && current_user_can($ptype->cap->edit_others_posts)) {
            if ('sticky' == $post_data['sticky']) {
                stick_post($post_ID);
            } else {
                unstick_post($post_ID);
            }
        }
        if (isset($post_data['post_format'])) {
            set_post_format($post_ID, $post_data['post_format']);
        }
    }
    return array('updated' => $updated, 'skipped' => $skipped, 'locked' => $locked);
}
Ejemplo n.º 9
0
/**
 * Print JavaScript templates required for the revisions experience.
 *
 * @since 4.1.0
 *
 * @global WP_Post $post The global `$post` object.
 */
function wp_print_revision_templates()
{
    global $post;
    ?>
<script id="tmpl-revisions-frame" type="text/html">
		<div class="revisions-control-frame"></div>
		<div class="revisions-diff-frame"></div>
	</script>

	<script id="tmpl-revisions-buttons" type="text/html">
		<div class="revisions-previous">
			<input class="button" type="button" value="<?php 
    echo esc_attr_x('Previous', 'Button label for a previous revision');
    ?>
" />
		</div>

		<div class="revisions-next">
			<input class="button" type="button" value="<?php 
    echo esc_attr_x('Next', 'Button label for a next revision');
    ?>
" />
		</div>
	</script>

	<script id="tmpl-revisions-checkbox" type="text/html">
		<div class="revision-toggle-compare-mode">
			<label>
				<input type="checkbox" class="compare-two-revisions"
				<#
				if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) {
					#> checked="checked"<#
				}
				#>
				/>
				<?php 
    esc_attr_e('Compare any two revisions');
    ?>
			</label>
		</div>
	</script>

	<script id="tmpl-revisions-meta" type="text/html">
		<# if ( ! _.isUndefined( data.attributes ) ) { #>
			<div class="diff-title">
				<# if ( 'from' === data.type ) { #>
					<strong><?php 
    _ex('From:', 'Followed by post revision info');
    ?>
</strong>
				<# } else if ( 'to' === data.type ) { #>
					<strong><?php 
    _ex('To:', 'Followed by post revision info');
    ?>
</strong>
				<# } #>
				<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
					{{{ data.attributes.author.avatar }}}
					<div class="author-info">
					<# if ( data.attributes.autosave ) { #>
						<span class="byline"><?php 
    printf(__('Autosave by %s'), '<span class="author-name">{{ data.attributes.author.name }}</span>');
    ?>
</span>
					<# } else if ( data.attributes.current ) { #>
						<span class="byline"><?php 
    printf(__('Current Revision by %s'), '<span class="author-name">{{ data.attributes.author.name }}</span>');
    ?>
</span>
					<# } else { #>
						<span class="byline"><?php 
    printf(__('Revision by %s'), '<span class="author-name">{{ data.attributes.author.name }}</span>');
    ?>
</span>
					<# } #>
						<span class="time-ago">{{ data.attributes.timeAgo }}</span>
						<span class="date">({{ data.attributes.dateShort }})</span>
					</div>
				<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
					<input  <?php 
    if (wp_check_post_lock($post->ID)) {
        ?>
						disabled="disabled"
					<?php 
    } else {
        ?>
						<# if ( data.attributes.current ) { #>
							disabled="disabled"
						<# } #>
					<?php 
    }
    ?>
					<# if ( data.attributes.autosave ) { #>
						type="button" class="restore-revision button button-primary" value="<?php 
    esc_attr_e('Restore This Autosave');
    ?>
" />
					<# } else { #>
						type="button" class="restore-revision button button-primary" value="<?php 
    esc_attr_e('Restore This Revision');
    ?>
" />
					<# } #>
				<# } #>
			</div>
		<# if ( 'tooltip' === data.type ) { #>
			<div class="revisions-tooltip-arrow"><span></span></div>
		<# } #>
	<# } #>
	</script>

	<script id="tmpl-revisions-diff" type="text/html">
		<div class="loading-indicator"><span class="spinner"></span></div>
		<div class="diff-error"><?php 
    _e('Sorry, something went wrong. The requested comparison could not be loaded.');
    ?>
</div>
		<div class="diff">
		<# _.each( data.fields, function( field ) { #>
			<h3>{{ field.name }}</h3>
			{{{ field.diff }}}
		<# }); #>
		</div>
	</script><?php 
}
Ejemplo n.º 10
0
/**
 * {@internal Missing Short Description}}
 *
 * Updates all bulk edited posts/pages, adding (but not removing) tags and
 * categories. Skips pages when they would be their own parent or child.
 *
 * @since unknown
 *
 * @return array
 */
function bulk_edit_posts($post_data = null)
{
    global $wpdb;
    if (empty($post_data)) {
        $post_data =& $_POST;
    }
    if (isset($post_data['post_type']) && 'page' == $post_data['post_type']) {
        if (!current_user_can('edit_pages')) {
            wp_die(__('You are not allowed to edit pages.'));
        }
    } else {
        if (!current_user_can('edit_posts')) {
            wp_die(__('You are not allowed to edit posts.'));
        }
    }
    $post_IDs = array_map('intval', (array) $post_data['post']);
    $reset = array('post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tags_input', 'post_category', 'sticky');
    foreach ($reset as $field) {
        if (isset($post_data[$field]) && ('' == $post_data[$field] || -1 == $post_data[$field])) {
            unset($post_data[$field]);
        }
    }
    if (isset($post_data['post_category'])) {
        if (is_array($post_data['post_category']) && !empty($post_data['post_category'])) {
            $new_cats = array_map(absint, $post_data['post_category']);
        } else {
            unset($post_data['post_category']);
        }
    }
    if (isset($post_data['tags_input'])) {
        $new_tags = preg_replace('/\\s*,\\s*/', ',', rtrim(trim($post_data['tags_input']), ' ,'));
        $new_tags = explode(',', $new_tags);
    }
    if (isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent'])) {
        $pages = $wpdb->get_results("SELECT ID, post_parent FROM {$wpdb->posts} WHERE post_type = 'page'");
        $children = array();
        for ($i = 0; $i < 50 && $parent > 0; $i++) {
            $children[] = $parent;
            foreach ($pages as $page) {
                if ($page->ID == $parent) {
                    $parent = $page->post_parent;
                    break;
                }
            }
        }
    }
    $updated = $skipped = $locked = array();
    foreach ($post_IDs as $post_ID) {
        if (isset($children) && in_array($post_ID, $children)) {
            $skipped[] = $post_ID;
            continue;
        }
        if (wp_check_post_lock($post_ID)) {
            $locked[] = $post_ID;
            continue;
        }
        if (isset($new_cats)) {
            $cats = (array) wp_get_post_categories($post_ID);
            $post_data['post_category'] = array_unique(array_merge($cats, $new_cats));
        }
        if (isset($new_tags)) {
            $tags = wp_get_post_tags($post_ID, array('fields' => 'names'));
            $post_data['tags_input'] = array_unique(array_merge($tags, $new_tags));
        }
        $post_data['ID'] = $post_ID;
        $updated[] = wp_update_post($post_data);
        if (current_user_can('edit_others_posts') && isset($post_data['sticky'])) {
            if ('sticky' == $post_data['sticky']) {
                stick_post($post_ID);
            } else {
                unstick_post($post_ID);
            }
        }
    }
    return array('updated' => $updated, 'skipped' => $skipped, 'locked' => $locked);
}
Ejemplo n.º 11
0
    function single_row($post, $level = 0)
    {
        global $mode;
        static $alternate;
        $global_post = get_post();
        $GLOBALS['post'] = $post;
        setup_postdata($post);
        $edit_link = get_edit_post_link($post->ID);
        $title = _draft_or_post_title();
        $post_type_object = get_post_type_object($post->post_type);
        $can_edit_post = current_user_can('edit_post', $post->ID);
        $alternate = 'alternate' == $alternate ? '' : 'alternate';
        $classes = $alternate . ' iedit author-' . (get_current_user_id() == $post->post_author ? 'self' : 'other');
        $lock_holder = wp_check_post_lock($post->ID);
        if ($lock_holder) {
            $classes .= ' wp-locked';
            $lock_holder = get_userdata($lock_holder);
        }
        if ($post->post_parent) {
            $count = count(get_post_ancestors($post->ID));
            $classes .= ' level-' . $count;
        } else {
            $classes .= ' level-0';
        }
        ?>
		<tr id="post-<?php 
        echo $post->ID;
        ?>
" class="<?php 
        echo implode(' ', get_post_class($classes, $post->ID));
        ?>
">
	<?php 
        list($columns, $hidden) = $this->get_column_info();
        foreach ($columns as $column_name => $column_display_name) {
            $class = "class=\"{$column_name} column-{$column_name}\"";
            $style = '';
            if (in_array($column_name, $hidden)) {
                $style = ' style="display:none;"';
            }
            $attributes = "{$class}{$style}";
            switch ($column_name) {
                case 'cb':
                    ?>
			<th scope="row" class="check-column">
				<label class="screen-reader-text" for="cb-select-<?php 
                    the_ID();
                    ?>
"><?php 
                    printf(__('Select %s'), $title);
                    ?>
</label>
				<input id="cb-select-<?php 
                    the_ID();
                    ?>
" type="checkbox" name="select_posts[]" value="<?php 
                    the_ID();
                    ?>
" data-post_id="<?php 
                    the_ID();
                    ?>
" data-post_type="<?php 
                    echo $post->post_type;
                    ?>
" />
				<?php 
                    if ($can_edit_post) {
                        ?>
				<div class="locked-indicator"></div>
				<?php 
                    }
                    ?>
			</th>
			<?php 
                    break;
                case 'title':
                    $attributes = 'class="post-title page-title column-title"' . $style;
                    if ($this->hierarchical_display) {
                        if (0 == $level && (int) $post->post_parent > 0) {
                            //sent level 0 by accident, by default, or because we don't know the actual level
                            $find_main_page = (int) $post->post_parent;
                            while ($find_main_page > 0) {
                                $parent = get_post($find_main_page);
                                if (is_null($parent)) {
                                    break;
                                }
                                $level++;
                                $find_main_page = (int) $parent->post_parent;
                                if (!isset($parent_name)) {
                                    /** This filter is documented in wp-includes/post-template.php */
                                    $parent_name = apply_filters('the_title', $parent->post_title, $parent->ID);
                                }
                            }
                        }
                    }
                    $pad = str_repeat('&#8212; ', $level);
                    echo "<td {$attributes}><strong>";
                    // post format filtering
                    if ($format = get_post_format($post->ID)) {
                        $label = get_post_format_string($format);
                        echo '<a href="' . fa_iframe_admin_page_url('fa-mixed-content-modal', array('post_format' => $format, 'post_type' => $post->post_type), false) . '" class="post-state-format post-format-icon post-format-' . $format . '" title="' . $label . '">' . $label . ":</a> ";
                    }
                    // Post title with edit link
                    if ($can_edit_post && $post->post_status != 'trash') {
                        echo '<a target="_blank" class="row-title" href="' . $edit_link . '" title="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)) . '">' . $pad . '<span id="fa-name-' . $post->ID . '">' . $title . '</span></a>';
                    } else {
                        echo $pad . '<span id="fa-name-' . $post->ID . '">' . $title . '</span>';
                    }
                    _post_states($post);
                    if (isset($parent_name)) {
                        echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html($parent_name);
                    }
                    echo "</strong>\n";
                    if ($can_edit_post && $post->post_status != 'trash') {
                        if ($lock_holder) {
                            $locked_avatar = get_avatar($lock_holder->ID, 18);
                            $locked_text = esc_html(sprintf(__('%s is currently editing'), $lock_holder->display_name));
                        } else {
                            $locked_avatar = $locked_text = '';
                        }
                        echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
                    }
                    if (!$this->hierarchical_display && 'excerpt' == $mode && current_user_can('read_post', $post->ID)) {
                        the_excerpt();
                    }
                    // actions
                    $actions = array();
                    // edit link
                    if ($can_edit_post && 'trash' != $post->post_status) {
                        $actions['edit'] = '<a target="_blank" href="' . get_edit_post_link($post->ID, true) . '" title="' . esc_attr(__('Edit this item')) . '">' . __('Edit') . '</a>';
                    }
                    // View/Preview links
                    if ($post_type_object->public) {
                        if (in_array($post->post_status, array('pending', 'draft', 'future'))) {
                            if ($can_edit_post) {
                                /** This filter is documented in wp-admin/includes/meta-boxes.php */
                                $actions['view'] = '<a target="_blank" href="' . esc_url(apply_filters('preview_post_link', set_url_scheme(add_query_arg('preview', 'true', get_permalink($post->ID))))) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
                            }
                        } elseif ('trash' != $post->post_status) {
                            $actions['view'] = '<a target="_blank" href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
                        }
                    }
                    if (is_post_type_hierarchical($post->post_type)) {
                        /**
                         * Filter the array of row action links on the Pages list table.
                         *
                         * The filter is evaluated only for hierarchical post types.
                         *
                         * @since 2.8.0
                         *
                         * @param array   $actions An array of row action links. Defaults are
                         *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
                         *                         'Delete Permanently', 'Preview', and 'View'.
                         * @param WP_Post $post    The post object.
                         */
                        $actions = apply_filters('fa_page_row_actions', $actions, $post);
                    } else {
                        /**
                         * Filter the array of row action links on the Posts list table.
                         *
                         * The filter is evaluated only for non-hierarchical post types.
                         *
                         * @since 2.8.0
                         *
                         * @param array   $actions An array of row action links. Defaults are
                         *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
                         *                         'Delete Permanently', 'Preview', and 'View'.
                         * @param WP_Post $post    The post object.
                         */
                        $actions = apply_filters('fa_post_row_actions', $actions, $post);
                    }
                    echo $this->row_actions($actions);
                    get_inline_data($post);
                    echo '</td>';
                    break;
                case 'slide_title':
                    $fa_slide = fa_get_slide_options($post->ID);
                    if (isset($fa_slide['title'])) {
                        echo '<td ' . $attributes . '>';
                        if ($post->post_title != $fa_slide['title']) {
                            echo '<strong>' . $fa_slide['title'] . '</strong>';
                        } else {
                            echo '<i>' . $fa_slide['title'] . '</i>';
                        }
                        echo '</td>';
                    }
                    break;
                case 'date':
                    if ('0000-00-00 00:00:00' == $post->post_date) {
                        $t_time = $h_time = __('Unpublished');
                        $time_diff = 0;
                    } else {
                        $t_time = get_the_time(__('Y/m/d g:i:s A'));
                        $m_time = $post->post_date;
                        $time = get_post_time('G', true, $post);
                        $time_diff = time() - $time;
                        if ($time_diff > 0 && $time_diff < DAY_IN_SECONDS) {
                            $h_time = sprintf(__('%s ago'), human_time_diff($time));
                        } else {
                            $h_time = mysql2date(__('Y/m/d'), $m_time);
                        }
                    }
                    echo '<td ' . $attributes . '>';
                    if ('excerpt' == $mode) {
                        /**
                         * Filter the published time of the post.
                         *
                         * If $mode equals 'excerpt', the published time and date are both displayed.
                         * If $mode equals 'list' (default), the publish date is displayed, with the
                         * time and date together available as an abbreviation definition.
                         *
                         * @since 2.5.1
                         *
                         * @param array   $t_time      The published time.
                         * @param WP_Post $post        Post object.
                         * @param string  $column_name The column name.
                         * @param string  $mode        The list display mode ('excerpt' or 'list').
                         */
                        echo apply_filters('fa_post_date_column_time', $t_time, $post, $column_name, $mode);
                    } else {
                        /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
                        echo '<abbr title="' . $t_time . '">' . apply_filters('fa_post_date_column_time', $h_time, $post, $column_name, $mode) . '</abbr>';
                    }
                    echo '<br />';
                    if ('publish' == $post->post_status) {
                        _e('Published');
                    } elseif ('future' == $post->post_status) {
                        if ($time_diff > 0) {
                            echo '<strong class="attention">' . __('Missed schedule') . '</strong>';
                        } else {
                            _e('Scheduled');
                        }
                    } else {
                        _e('Last Modified');
                    }
                    echo '</td>';
                    break;
                case 'comments':
                    ?>
			<td <?php 
                    echo $attributes;
                    ?>
><div class="post-com-count-wrapper">
			<?php 
                    $pending_comments = isset($this->comment_pending_count[$post->ID]) ? $this->comment_pending_count[$post->ID] : 0;
                    ?>
				<strong class="post-com-count"><span><?php 
                    echo $pending_comments;
                    ?>
</span></strong>
			</div></td>
			<?php 
                    break;
                case 'author':
                    ?>
			<td <?php 
                    echo $attributes;
                    ?>
><?php 
                    printf('<a href="%s">%s</a>', fa_iframe_admin_page_url('fa-mixed-content-modal', array('post_type' => $post->post_type, 'author' => get_the_author_meta('ID')), false), get_the_author());
                    ?>
</td>
			<?php 
                    break;
                default:
                    if ('categories' == $column_name) {
                        $taxonomy = 'category';
                    } elseif ('tags' == $column_name) {
                        $taxonomy = 'post_tag';
                    } elseif (0 === strpos($column_name, 'taxonomy-')) {
                        $taxonomy = substr($column_name, 9);
                    } else {
                        $taxonomy = false;
                    }
                    if ($taxonomy) {
                        $taxonomy_object = get_taxonomy($taxonomy);
                        echo '<td ' . $attributes . '>';
                        if ($terms = get_the_terms($post->ID, $taxonomy)) {
                            $out = array();
                            foreach ($terms as $t) {
                                $posts_in_term_qv = array();
                                $posts_in_term_qv['post_type'] = $post->post_type;
                                if ($taxonomy_object->query_var) {
                                    $posts_in_term_qv[$taxonomy_object->query_var] = $t->slug;
                                } else {
                                    $posts_in_term_qv['taxonomy'] = $taxonomy;
                                    $posts_in_term_qv['term'] = $t->slug;
                                }
                                $out[] = sprintf('<a href="%s">%s</a>', fa_iframe_admin_page_url('fa-mixed-content-modal', $posts_in_term_qv, false), esc_html(sanitize_term_field('name', $t->name, $t->term_id, $taxonomy, 'display')));
                            }
                            /* translators: used between list items, there is a space after the comma */
                            echo join(__(', '), $out);
                        } else {
                            echo '&#8212;';
                        }
                        echo '</td>';
                        break;
                    }
                    ?>
			<td <?php 
                    echo $attributes;
                    ?>
><?php 
                    if (is_post_type_hierarchical($post->post_type)) {
                        /**
                         * Fires in each custom column on the Posts list table.
                         *
                         * This hook only fires if the current post type is hierarchical,
                         * such as pages.
                         *
                         * @since 2.5.0
                         *
                         * @param string $column_name The name of the column to display.
                         * @param int    $post_id     The current post ID.
                         */
                        do_action('fa_manage_pages_custom_column', $column_name, $post->ID);
                    } else {
                        /**
                         * Fires in each custom column in the Posts list table.
                         *
                         * This hook only fires if the current post type is non-hierarchical,
                         * such as posts.
                         *
                         * @since 1.5.0
                         *
                         * @param string $column_name The name of the column to display.
                         * @param int    $post_id     The current post ID.
                         */
                        do_action('fa_manage_posts_custom_column', $column_name, $post->ID);
                    }
                    /**
                     * Fires for each custom column of a specific post type in the Posts list table.
                     *
                     * The dynamic portion of the hook name, $post->post_type, refers to the post type.
                     *
                     * @since 3.1.0
                     *
                     * @param string $column_name The name of the column to display.
                     * @param int    $post_id     The current post ID.
                     */
                    do_action("fa_manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID);
                    ?>
</td>
			<?php 
                    break;
            }
        }
        ?>
		</tr>
	<?php 
        $GLOBALS['post'] = $global_post;
    }
Ejemplo n.º 12
0
 if (empty($post->ID)) {
     wp_die(__("You attempted to edit a page that doesn't exist. Perhaps it was deleted?"));
 }
 if ('page' != $post->post_type) {
     wp_redirect(get_edit_post_link($post_ID, 'url'));
     exit;
 }
 wp_enqueue_script('page');
 if (user_can_richedit()) {
     wp_enqueue_script('editor');
 }
 add_thickbox();
 wp_enqueue_script('media-upload');
 wp_enqueue_script('word-count');
 if (current_user_can('edit_page', $page_ID)) {
     if ($last = wp_check_post_lock($post->ID)) {
         $last_user = get_userdata($last);
         $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
         $message = sprintf(__('Warning: %s is currently editing this page'), wp_specialchars($last_user_name));
         $message = str_replace("'", "\\'", "<div class='error'><p>{$message}</p></div>");
         add_action('admin_notices', create_function('', "echo '{$message}';"));
     } else {
         wp_set_post_lock($post->ID);
         wp_enqueue_script('autosave');
     }
 }
 require_once 'admin-header.php';
 if (!current_user_can('edit_page', $page_ID)) {
     die(__('You are not allowed to edit this page.'));
 }
 include 'edit-page-form.php';
Ejemplo n.º 13
0
/**
 * Check lock status on the New/Edit Post screen and refresh the lock
 *
 * @since 3.6.0
 *
 * @param array  $response  The Heartbeat response.
 * @param array  $data      The $_POST data sent.
 * @param string $screen_id The screen id.
 * @return array The Heartbeat response.
 */
function wp_refresh_post_lock($response, $data, $screen_id)
{
    if (array_key_exists('wp-refresh-post-lock', $data)) {
        $received = $data['wp-refresh-post-lock'];
        $send = array();
        if (!($post_id = absint($received['post_id']))) {
            return $response;
        }
        if (!current_user_can('edit_post', $post_id)) {
            return $response;
        }
        if (($user_id = wp_check_post_lock($post_id)) && ($user = get_userdata($user_id))) {
            $error = array('text' => sprintf(__('%s has taken over and is currently editing.'), $user->display_name));
            if ($avatar = get_avatar($user->ID, 64)) {
                if (preg_match("|src='([^']+)'|", $avatar, $matches)) {
                    $error['avatar_src'] = $matches[1];
                }
            }
            $send['lock_error'] = $error;
        } else {
            if ($new_lock = wp_set_post_lock($post_id)) {
                $send['new_lock'] = implode(':', $new_lock);
            }
        }
        $response['wp-refresh-post-lock'] = $send;
    }
    return $response;
}
Ejemplo n.º 14
0
     $post_ids = explode(',', $_REQUEST['ids']);
 } elseif (!empty($_REQUEST['post'])) {
     $post_ids = array_map('intval', $_REQUEST['post']);
 }
 if (!isset($post_ids)) {
     wp_redirect($sendback);
     exit;
 }
 switch ($doaction) {
     case 'trash':
         $trashed = $locked = 0;
         foreach ((array) $post_ids as $post_id) {
             if (!current_user_can('delete_post', $post_id)) {
                 wp_die(__('You are not allowed to move this item to the Trash.'));
             }
             if (wp_check_post_lock($post_id)) {
                 $locked++;
                 continue;
             }
             if (!wp_trash_post($post_id)) {
                 wp_die(__('Error in moving to Trash.'));
             }
             $trashed++;
         }
         $sendback = add_query_arg(array('trashed' => $trashed, 'ids' => join(',', $post_ids), 'locked' => $locked), $sendback);
         break;
     case 'untrash':
         $untrashed = 0;
         foreach ((array) $post_ids as $post_id) {
             if (!current_user_can('delete_post', $post_id)) {
                 wp_die(__('You are not allowed to restore this item from the Trash.'));
Ejemplo n.º 15
0
 function body_class($classes)
 {
     global $post;
     $classes[] = 'fee fee-off';
     require_once ABSPATH . '/wp-admin/includes/post.php';
     if (wp_check_post_lock($post->ID)) {
         $classes[] = 'fee-locked';
     }
     return $classes;
 }
Ejemplo n.º 16
0
 /**
  * Catches page loads, determines what to do, and sends users on their merry way
  *
  * @package BuddyPress Docs
  * @since 1.0-beta
  */
 function catch_page_load()
 {
     global $bp;
     if (!empty($_POST['doc-edit-submit'])) {
         $this_doc = new BP_Docs_Query();
         $this_doc->save();
     }
     if (!empty($_POST['docs-filter-submit'])) {
         $this->handle_filters();
     }
     // If this is the edit screen, ensure that the user can edit the
     // doc before querying, and redirect if necessary
     if (!empty($bp->bp_docs->current_view) && 'edit' == $bp->bp_docs->current_view) {
         if (bp_docs_current_user_can('edit')) {
             $doc = bp_docs_get_current_doc();
             // The user can edit, so we check for edit locks
             // Because we're not using WP autosave at the moment, ensure that
             // the lock interval always returns as in process
             add_filter('wp_check_post_lock_window', create_function(false, 'return time();'));
             $lock = wp_check_post_lock($doc->ID);
             if ($lock) {
                 bp_core_add_message(sprintf(__('This doc is currently being edited by %s. To prevent overwrites, you cannot edit until that user has finished. Please try again in a few minutes.', 'bp-docs'), bp_core_get_user_displayname($lock)), 'error');
                 $group_permalink = bp_get_group_permalink($bp->groups->current_group);
                 $doc_slug = $bp->bp_docs->doc_slug;
                 // Redirect back to the non-edit view of this document
                 bp_core_redirect($group_permalink . $bp->bp_docs->slug . '/' . $doc_slug);
             }
         } else {
             // The user does not have edit permission. Redirect.
             bp_core_add_message(__('You do not have permission to edit the doc.', 'bp-docs'), 'error');
             $group_permalink = bp_get_group_permalink($bp->groups->current_group);
             $doc_slug = $bp->bp_docs->doc_slug;
             // Redirect back to the non-edit view of this document
             bp_core_redirect($group_permalink . $bp->bp_docs->slug . '/' . $doc_slug);
         }
     }
     if (!empty($bp->bp_docs->current_view) && 'create' == $bp->bp_docs->current_view) {
         if (!bp_docs_current_user_can('create')) {
             // The user does not have edit permission. Redirect.
             bp_core_add_message(__('You do not have permission to create a Doc in this group.', 'bp-docs'), 'error');
             $group_permalink = bp_get_group_permalink($bp->groups->current_group);
             // Redirect back to the Doc list view
             bp_core_redirect($group_permalink . $bp->bp_docs->slug . '/');
         }
     }
     if (!empty($bp->bp_docs->current_view) && 'history' == $bp->bp_docs->current_view) {
         if (!bp_docs_current_user_can('view_history')) {
             // The user does not have edit permission. Redirect.
             bp_core_add_message(__('You do not have permission to view this Doc\'s history.', 'bp-docs'), 'error');
             $doc = bp_docs_get_current_doc();
             $redirect = bp_docs_get_doc_link($doc->ID);
             // Redirect back to the Doc list view
             bp_core_redirect($redirect);
         }
     }
     // Cancel edit lock
     if (!empty($_GET['bpd_action']) && $_GET['bpd_action'] == 'cancel_edit_lock') {
         // Check the nonce
         check_admin_referer('bp_docs_cancel_edit_lock');
         // Todo: make this part of the perms system
         if (is_super_admin() || bp_group_is_admin()) {
             $doc = bp_docs_get_current_doc();
             // Todo: get this into a proper method as well, blech
             delete_post_meta($doc->ID, '_edit_lock');
             bp_core_add_message(__('Lock successfully removed', 'bp-docs'));
             bp_core_redirect(bp_docs_get_doc_link($doc->ID));
         }
     }
     // Cancel edit
     // Have to have a catcher for this so the edit lock can be removed
     if (!empty($_GET['bpd_action']) && $_GET['bpd_action'] == 'cancel_edit') {
         $doc = bp_docs_get_current_doc();
         // Todo: get this into a proper method as well, blech
         delete_post_meta($doc->ID, '_edit_lock');
         bp_core_redirect(bp_docs_get_doc_link($doc->ID));
     }
     // Todo: get this into a proper method
     if ($bp->bp_docs->current_view == 'delete') {
         check_admin_referer('bp_docs_delete');
         if (bp_docs_current_user_can('manage')) {
             $the_doc_args = array('name' => $bp->action_variables[0], 'post_type' => $bp->bp_docs->post_type_name);
             $the_docs = get_posts($the_doc_args);
             $doc_id = $the_docs[0]->ID;
             do_action('bp_docs_before_doc_delete', $doc_id);
             $delete_args = array('ID' => $doc_id, 'post_status' => 'trash');
             wp_update_post($delete_args);
             do_action('bp_docs_doc_deleted', $delete_args);
             bp_core_add_message(__('Doc successfully deleted!', 'bp-docs'));
         } else {
             bp_core_add_message(__('You do not have permission to delete that doc.', 'bp-docs'), 'error');
         }
         // todo: abstract this out so I don't have to call group permalink here
         $redirect_url = bp_get_group_permalink($bp->groups->current_group) . $bp->bp_docs->slug . '/';
         bp_core_redirect($redirect_url);
     }
 }
Ejemplo n.º 17
0
			<a href="#" class="np-btn clone-post" data-id="<?php 
    echo get_the_id();
    ?>
" data-parentname="<?php 
    echo $this->post->title;
    ?>
"><?php 
    _e('Clone', 'nestedpages');
    ?>
</a>
			<?php 
}
?>

			<?php 
if (!($user = wp_check_post_lock($this->post->id) || !$this->integrations->plugins->editorial_access_manager->hasAccess($this->post->id))) {
    ?>
			<a href="#" 
				class="np-btn np-quick-edit" 
				data-id="<?php 
    echo $this->post->id;
    ?>
" 
				data-template="<?php 
    echo $this->post->template;
    ?>
" 
				data-title="<?php 
    echo $this->post->title;
    ?>
" 
 /**
  * default method for the 'edit' route for cpt admin pages
  *
  * For reference on what to put in here, refer to wp-admin/post.php
  *
  * @access protected
  * @return string   template for edit cpt form
  */
 protected function _edit_cpt_item()
 {
     global $post, $title, $is_IE, $post_type, $post_type_object;
     $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : NULL;
     $post = !empty($post_id) ? get_post($post_id, OBJECT, 'edit') : NULL;
     if (empty($post)) {
         wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
     }
     if (!empty($_GET['get-post-lock'])) {
         wp_set_post_lock($post_id);
         wp_redirect(get_edit_post_link($post_id, 'url'));
         exit;
     }
     $editing = TRUE;
     $post_ID = $post_id;
     $post = $post;
     $post_type = $this->_cpt_routes[$this->_req_action];
     $post_type_object = $this->_cpt_object;
     $is_IE = $is_IE;
     if (!wp_check_post_lock($post->ID)) {
         $active_post_lock = wp_set_post_lock($post->ID);
         //wp_enqueue_script('autosave');
     }
     $title = $this->_cpt_object->labels->edit_item;
     add_action('admin_footer', '_admin_notice_post_locked');
     if (isset($this->_cpt_routes[$this->_req_data['action']]) && !isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])) {
         $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', 'create_new', $this);
         $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array('action' => $create_new_action, 'page' => $this->page_slug), 'admin.php');
     }
     if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
         wp_enqueue_script('admin-comments');
         enqueue_comment_hotkeys_js();
     }
     add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
     //modify the default editor title field with default title.
     add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
     include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
 }
Ejemplo n.º 19
0
 function start_el(&$output, $page, $depth, $args)
 {
     if ($depth) {
         $indent = str_repeat("\t", $depth);
     } else {
         $indent = '';
     }
     extract($args, EXTR_SKIP);
     // Post States
     $page_states = array();
     if ($user_id = wp_check_post_lock($page->ID)) {
         $user = get_userdata($user_id);
         $page_states['post-lock'] = sprintf(__('! %s is editing this page. Page order might be overwritten.', 'cms-page-order'), $user->display_name);
     }
     // Password protected?
     if (!empty($page->post_password)) {
         $page_states['password'] = __('Password protected', 'cms-page-order');
     }
     // Check post status, but skip published pages.
     if ($page->post_status !== 'publish') {
         $page_states[$page->post_status] = $page->post_status;
     }
     // Text for the labels
     foreach ($page_states as $state => $state_name) {
         // Don't list private pages if user is not allowed read them
         if ($state == 'private') {
             if (!current_user_can('read_private_pages')) {
                 return;
             }
         }
         if (in_array($state, array('private', 'draft', 'pending'))) {
             $page_states[$state] = __(ucfirst($state));
         } elseif ($state == 'future') {
             $page_states[$state] = __('Scheduled', 'cms-page-order');
         } elseif ($state !== 'password' && empty($state_name)) {
             $page_states[$state] = ucfirst($state);
         }
     }
     // Set date_i18n( __( 'M j Y @ H:i' ), strtotime( $page->post_date ) ) as title on scheduled posts
     $state_labels = null;
     foreach ($page_states as $state => $state_name) {
         $title = null;
         // Text for the title attribute
         if (in_array($state, array('password', 'private'))) {
             $title = __('Make page public', 'cms-page-order');
         } elseif (in_array($state, array('draft', 'pending', 'future'))) {
             $title = __('Publish page', 'cms-page-order');
         }
         $post_type = esc_attr($_GET['post_type']);
         if (in_array($state, array('draft', 'pending', 'future', 'private', 'password'))) {
             $action_url = wp_nonce_url('?post_type=' . $post_type . '&page=order&post=' . $page->ID . '&action=remove_label&state=' . $state, 'cms-page-order');
         }
         if ($state == 'private' && !current_user_can('edit_private_pages')) {
             $action_url = null;
         } else {
             $action = null;
         }
         if (!empty($action_url)) {
             $action = '<a title="' . $title . '" href="' . $action_url . '" class="cmspo-delete">x</a>';
         }
         $state_labels .= '<span class="cmspo-state ' . $state . '">' . $state_name . ' ' . $action . '</span> ';
     }
     if ($children_count = cmspo_has_children($page->ID)) {
         $children_count = ' <span class="cmspo-count">(' . $children_count . ')</span>';
         if (($state = cmspo_get_user_option('cmspo_tree_state')) && in_array($page->ID, $state)) {
             $output .= $indent . '<li id="page-' . $page->ID . '" class="cmspo-open">';
         } else {
             $output .= $indent . '<li id="page-' . $page->ID . '" class="cmspo-closed">';
         }
     } else {
         $output .= $indent . '<li id="page-' . $page->ID . '">';
         $children_count = ' <span class="cmspo-count"></span>';
     }
     $output .= '<div class="cmspo-page">' . $state_labels . apply_filters('the_title', $page->post_title, $page->ID) . $children_count . ' <span class="cmspo-page-actions">' . '<a class="cmspo-edit" href="' . get_permalink($page->ID) . '">' . __('View') . '</a>';
     // can has capabilities to edit this page?
     if ($edit = get_edit_post_link($page->ID)) {
         $output .= ' | <a class="cmspo-edit" href="' . $edit . '">' . __('Edit') . '</a>';
     }
     // can has capabilities to delete this page?
     if ($delete = get_delete_post_link($page->ID)) {
         $output .= ' | <a class="cmspo-delete" href="' . $delete . '">' . _x('Trash', 'verb') . '</a>';
     }
     $output .= '</span>' . '</div>';
 }
Ejemplo n.º 20
0
/**
 * Save draft or manually autosave for showing preview.
 *
 * @package WordPress
 * @since 2.7.0
 *
 * @uses get_post_status()
 * @uses edit_post()
 * @uses get_post()
 * @uses current_user_can()
 * @uses wp_die()
 * @uses wp_create_post_autosave()
 * @uses add_query_arg()
 * @uses wp_create_nonce()
 *
 * @return str URL to redirect to show the preview
 */
function post_preview()
{
    $post_ID = (int) $_POST['post_ID'];
    $status = get_post_status($post_ID);
    if ('auto-draft' == $status) {
        wp_die(__('Preview not available. Please save as a draft first.'));
    }
    if (isset($_POST['catslist'])) {
        $_POST['post_category'] = explode(",", $_POST['catslist']);
    }
    if (isset($_POST['tags_input'])) {
        $_POST['tags_input'] = explode(",", $_POST['tags_input']);
    }
    if ($_POST['post_type'] == 'page' || empty($_POST['post_category'])) {
        unset($_POST['post_category']);
    }
    $_POST['ID'] = $post_ID;
    $post = get_post($post_ID);
    if ('page' == $post->post_type) {
        if (!current_user_can('edit_page', $post_ID)) {
            wp_die(__('You are not allowed to edit this page.'));
        }
    } else {
        if (!current_user_can('edit_post', $post_ID)) {
            wp_die(__('You are not allowed to edit this post.'));
        }
    }
    $user_id = get_current_user_id();
    $locked = wp_check_post_lock($post->ID);
    if (!$locked && 'draft' == $post->post_status && $user_id == $post->post_author) {
        $id = edit_post();
    } else {
        // Non drafts are not overwritten. The autosave is stored in a special post revision.
        $id = wp_create_post_autosave($post->ID);
        if (!is_wp_error($id)) {
            $id = $post->ID;
        }
    }
    if (is_wp_error($id)) {
        wp_die($id->get_error_message());
    }
    if (!$locked && $_POST['post_status'] == 'draft' && $user_id == $post->post_author) {
        $url = add_query_arg('preview', 'true', get_permalink($id));
    } else {
        $nonce = wp_create_nonce('post_preview_' . $id);
        $args = array('preview' => 'true', 'preview_id' => $id, 'preview_nonce' => $nonce);
        if (isset($_POST['post_format'])) {
            $args['post_format'] = empty($_POST['post_format']) ? 'standard' : sanitize_key($_POST['post_format']);
        }
        $url = add_query_arg($args, get_permalink($id));
    }
    return apply_filters('preview_post_link', $url);
}
Ejemplo n.º 21
0
/**
 * Save a post submitted with XHR
 *
 * Intended for use with heartbeat and autosave.js
 *
 * @since 3.9.0
 *
 * @param array $post_data Associative array of the submitted post data.
 * @return mixed The value 0 or WP_Error on failure. The saved post ID on success.
 *               The ID can be the draft post_id or the autosave revision post_id.
 */
function wp_autosave($post_data)
{
    // Back-compat
    if (!defined('DOING_AUTOSAVE')) {
        define('DOING_AUTOSAVE', true);
    }
    $post_id = (int) $post_data['post_id'];
    $post_data['ID'] = $post_data['post_ID'] = $post_id;
    if (false === wp_verify_nonce($post_data['_wpnonce'], 'update-post_' . $post_id)) {
        return new WP_Error('invalid_nonce', __('Error while saving.'));
    }
    $post = get_post($post_id);
    if (!current_user_can('edit_post', $post->ID)) {
        return new WP_Error('edit_posts', __('Sorry, you are not allowed to edit this item.'));
    }
    if ('auto-draft' == $post->post_status) {
        $post_data['post_status'] = 'draft';
    }
    if ($post_data['post_type'] != 'page' && !empty($post_data['catslist'])) {
        $post_data['post_category'] = explode(',', $post_data['catslist']);
    }
    if (!wp_check_post_lock($post->ID) && get_current_user_id() == $post->post_author && ('auto-draft' == $post->post_status || 'draft' == $post->post_status)) {
        // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked
        return edit_post(wp_slash($post_data));
    } else {
        // Non drafts or other users drafts are not overwritten. The autosave is stored in a special post revision for each user.
        return wp_create_post_autosave(wp_slash($post_data));
    }
}
    function single_row($post, $level = 0)
    {
        global $mode;
        static $alternate;
        $global_post = get_post();
        $GLOBALS['post'] = $post;
        setup_postdata($post);
        $edit_link = get_edit_post_link($post->ID);
        $title = _draft_or_post_title();
        $post_type_object = get_post_type_object($post->post_type);
        $can_edit_post = current_user_can('edit_post', $post->ID);
        $alternate = 'alternate' == $alternate ? '' : 'alternate';
        $classes = $alternate . ' iedit author-' . (get_current_user_id() == $post->post_author ? 'self' : 'other');
        $lock_holder = wp_check_post_lock($post->ID);
        if ($lock_holder) {
            $classes .= ' wp-locked';
            $lock_holder = get_userdata($lock_holder);
        }
        ?>
		<tr id="post-<?php 
        echo $post->ID;
        ?>
" class="<?php 
        echo implode(' ', get_post_class($classes, $post->ID));
        ?>
" valign="top">
	<?php 
        list($columns, $hidden) = $this->get_column_info();
        foreach ($columns as $column_name => $column_display_name) {
            $class = "class=\"{$column_name} column-{$column_name}\"";
            $style = '';
            if (in_array($column_name, $hidden)) {
                $style = ' style="display:none;"';
            }
            $attributes = "{$class}{$style}";
            switch ($column_name) {
                case 'cb':
                    ?>
			<th scope="row" class="check-column">
				<?php 
                    if ($can_edit_post) {
                        ?>
				<label class="screen-reader-text" for="cb-select-<?php 
                        the_ID();
                        ?>
"><?php 
                        printf(__('Select %s'), $title);
                        ?>
</label>
				<input id="cb-select-<?php 
                        the_ID();
                        ?>
" type="checkbox" name="post[]" value="<?php 
                        the_ID();
                        ?>
" />
				<div class="locked-indicator"></div>
				<?php 
                    }
                    ?>
			</th>
			<?php 
                    break;
                case 'title':
                    $attributes = 'class="post-title page-title column-title"' . $style;
                    if ($this->hierarchical_display) {
                        if (0 == $level && (int) $post->post_parent > 0) {
                            //sent level 0 by accident, by default, or because we don't know the actual level
                            $find_main_page = (int) $post->post_parent;
                            while ($find_main_page > 0) {
                                $parent = get_post($find_main_page);
                                if (is_null($parent)) {
                                    break;
                                }
                                $level++;
                                $find_main_page = (int) $parent->post_parent;
                                if (!isset($parent_name)) {
                                    /** This filter is documented in wp-includes/post-template.php */
                                    $parent_name = apply_filters('the_title', $parent->post_title, $parent->ID);
                                }
                            }
                        }
                    }
                    $pad = str_repeat('&#8212; ', $level);
                    echo "<td {$attributes}><strong>";
                    if ($format = get_post_format($post->ID)) {
                        $label = get_post_format_string($format);
                        echo '<a href="' . esc_url(add_query_arg(array('post_format' => $format, 'post_type' => $post->post_type), 'edit.php')) . '" class="post-state-format post-format-icon post-format-' . $format . '" title="' . $label . '">' . $label . ":</a> ";
                    }
                    if ($can_edit_post && $post->post_status != 'trash') {
                        echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)) . '">' . $pad . $title . '</a>';
                    } else {
                        echo $pad . $title;
                    }
                    _post_states($post);
                    if (isset($parent_name)) {
                        echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html($parent_name);
                    }
                    echo "</strong>\n";
                    if ($can_edit_post && $post->post_status != 'trash') {
                        if ($lock_holder) {
                            $locked_avatar = get_avatar($lock_holder->ID, 18);
                            $locked_text = esc_html(sprintf(__('%s is currently editing'), $lock_holder->display_name));
                        } else {
                            $locked_avatar = $locked_text = '';
                        }
                        echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
                    }
                    if (!$this->hierarchical_display && 'excerpt' == $mode && current_user_can('read_post', $post->ID)) {
                        the_excerpt();
                    }
                    $actions = array();
                    if ($can_edit_post && 'trash' != $post->post_status) {
                        $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '" title="' . esc_attr(__('Edit this item')) . '">' . __('Edit') . '</a>';
                        $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this item inline')) . '">' . __('Quick&nbsp;Edit') . '</a>';
                    }
                    if (current_user_can('delete_post', $post->ID)) {
                        if ('trash' == $post->post_status) {
                            $actions['untrash'] = "<a title='" . esc_attr(__('Restore this item from the Trash')) . "' href='" . wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&amp;action=untrash', $post->ID)), 'untrash-post_' . $post->ID) . "'>" . __('Restore') . "</a>";
                        } elseif (EMPTY_TRASH_DAYS) {
                            $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this item to the Trash')) . "' href='" . get_delete_post_link($post->ID) . "'>" . __('Trash') . "</a>";
                        }
                        if ('trash' == $post->post_status || !EMPTY_TRASH_DAYS) {
                            $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this item permanently')) . "' href='" . get_delete_post_link($post->ID, '', true) . "'>" . __('Delete Permanently') . "</a>";
                        }
                    }
                    if ($post_type_object->public) {
                        if (in_array($post->post_status, array('pending', 'draft', 'future'))) {
                            if ($can_edit_post) {
                                $actions['view'] = '<a href="' . esc_url(apply_filters('preview_post_link', set_url_scheme(add_query_arg('preview', 'true', get_permalink($post->ID))))) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
                            }
                        } elseif ('trash' != $post->post_status) {
                            $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
                        }
                    }
                    $actions = apply_filters(is_post_type_hierarchical($post->post_type) ? 'page_row_actions' : 'post_row_actions', $actions, $post);
                    echo $this->row_actions($actions);
                    get_inline_data($post);
                    echo '</td>';
                    break;
                case 'date':
                    if ('0000-00-00 00:00:00' == $post->post_date) {
                        $t_time = $h_time = __('Unpublished');
                        $time_diff = 0;
                    } else {
                        $t_time = get_the_time(__('Y/m/d g:i:s A'));
                        $m_time = $post->post_date;
                        $time = get_post_time('G', true, $post);
                        $time_diff = time() - $time;
                        if ($time_diff > 0 && $time_diff < DAY_IN_SECONDS) {
                            $h_time = sprintf(__('%s ago'), human_time_diff($time));
                        } else {
                            $h_time = mysql2date(__('Y/m/d'), $m_time);
                        }
                    }
                    echo '<td ' . $attributes . '>';
                    if ('excerpt' == $mode) {
                        echo apply_filters('post_date_column_time', $t_time, $post, $column_name, $mode);
                    } else {
                        echo '<abbr title="' . $t_time . '">' . apply_filters('post_date_column_time', $h_time, $post, $column_name, $mode) . '</abbr>';
                    }
                    echo '<br />';
                    if ('publish' == $post->post_status) {
                        _e('Published');
                    } elseif ('future' == $post->post_status) {
                        if ($time_diff > 0) {
                            echo '<strong class="attention">' . __('Missed schedule') . '</strong>';
                        } else {
                            _e('Scheduled');
                        }
                    } else {
                        _e('Last Modified');
                    }
                    echo '</td>';
                    break;
                case 'comments':
                    ?>
			<td <?php 
                    echo $attributes;
                    ?>
><div class="post-com-count-wrapper">
			<?php 
                    $pending_comments = isset($this->comment_pending_count[$post->ID]) ? $this->comment_pending_count[$post->ID] : 0;
                    $this->comments_bubble($post->ID, $pending_comments);
                    ?>
			</div></td>
			<?php 
                    break;
                case 'author':
                    ?>
			<td <?php 
                    echo $attributes;
                    ?>
><?php 
                    printf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post_type' => $post->post_type, 'author' => get_the_author_meta('ID')), 'edit.php')), get_the_author());
                    ?>
</td>
			<?php 
                    break;
                default:
                    if ('categories' == $column_name) {
                        $taxonomy = 'category';
                    } elseif ('tags' == $column_name) {
                        $taxonomy = 'post_tag';
                    } elseif (0 === strpos($column_name, 'taxonomy-')) {
                        $taxonomy = substr($column_name, 9);
                    } else {
                        $taxonomy = false;
                    }
                    if ($taxonomy) {
                        $taxonomy_object = get_taxonomy($taxonomy);
                        echo '<td ' . $attributes . '>';
                        if ($terms = get_the_terms($post->ID, $taxonomy)) {
                            $out = array();
                            foreach ($terms as $t) {
                                $posts_in_term_qv = array();
                                if ('post' != $post->post_type) {
                                    $posts_in_term_qv['post_type'] = $post->post_type;
                                }
                                if ($taxonomy_object->query_var) {
                                    $posts_in_term_qv[$taxonomy_object->query_var] = $t->slug;
                                } else {
                                    $posts_in_term_qv['taxonomy'] = $taxonomy;
                                    $posts_in_term_qv['term'] = $t->slug;
                                }
                                $out[] = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg($posts_in_term_qv, 'edit.php')), esc_html(sanitize_term_field('name', $t->name, $t->term_id, $taxonomy, 'display')));
                            }
                            /* translators: used between list items, there is a space after the comma */
                            echo join(__(', '), $out);
                        } else {
                            echo '&#8212;';
                        }
                        echo '</td>';
                        break;
                    }
                    ?>
			<td <?php 
                    echo $attributes;
                    ?>
><?php 
                    if (is_post_type_hierarchical($post->post_type)) {
                        do_action('manage_pages_custom_column', $column_name, $post->ID);
                    } else {
                        do_action('manage_posts_custom_column', $column_name, $post->ID);
                    }
                    do_action("manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID);
                    ?>
</td>
			<?php 
                    break;
            }
        }
        ?>
		</tr>
	<?php 
        $GLOBALS['post'] = $global_post;
    }
Ejemplo n.º 23
0
					<span class="byline"><?php 
printf(__('Current Revision by %s'), '<span class="author-name">{{ data.attributes.author.name }}</span>');
?>
</span>
				<# } else { #>
					<span class="byline"><?php 
printf(__('Revision by %s'), '<span class="author-name">{{ data.attributes.author.name }}</span>');
?>
</span>
				<# } #>
					<span class="time-ago">{{ data.attributes.timeAgo }}</span>
					<span class="date">({{ data.attributes.dateShort }})</span>
				</div>
			<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
				<input  <?php 
if (wp_check_post_lock($post->ID)) {
    ?>
					disabled="disabled"
				<?php 
} else {
    ?>
					<# if ( data.attributes.current ) { #>
						disabled="disabled"
					<# } #>
				<?php 
}
?>
				<# if ( data.attributes.autosave ) { #>
					type="button" class="restore-revision button button-primary" value="<?php 
esc_attr_e('Restore This Autosave');
?>
Ejemplo n.º 24
0
/**
 * Ajax handler for Quick Edit saving a post from a list table.
 *
 * @since 3.1.0
 *
 * @global WP_List_Table $wp_list_table
 */
function wp_ajax_inline_save()
{
    global $wp_list_table, $mode;
    check_ajax_referer('inlineeditnonce', '_inline_edit');
    if (!isset($_POST['post_ID']) || !($post_ID = (int) $_POST['post_ID'])) {
        wp_die();
    }
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_ID)) {
            wp_die(__('You are not allowed to edit this page.'));
        }
    } else {
        if (!current_user_can('edit_post', $post_ID)) {
            wp_die(__('You are not allowed to edit this post.'));
        }
    }
    if ($last = wp_check_post_lock($post_ID)) {
        $last_user = get_userdata($last);
        $last_user_name = $last_user ? $last_user->display_name : __('Someone');
        printf($_POST['post_type'] == 'page' ? __('Saving is disabled: %s is currently editing this page.') : __('Saving is disabled: %s is currently editing this post.'), esc_html($last_user_name));
        wp_die();
    }
    $data =& $_POST;
    $post = get_post($post_ID, ARRAY_A);
    // Since it's coming from the database.
    $post = wp_slash($post);
    $data['content'] = $post['post_content'];
    $data['excerpt'] = $post['post_excerpt'];
    // Rename.
    $data['user_ID'] = get_current_user_id();
    if (isset($data['post_parent'])) {
        $data['parent_id'] = $data['post_parent'];
    }
    // Status.
    if (isset($data['keep_private']) && 'private' == $data['keep_private']) {
        $data['visibility'] = 'private';
        $data['post_status'] = 'private';
    } else {
        $data['post_status'] = $data['_status'];
    }
    if (empty($data['comment_status'])) {
        $data['comment_status'] = 'closed';
    }
    if (empty($data['ping_status'])) {
        $data['ping_status'] = 'closed';
    }
    // Exclude terms from taxonomies that are not supposed to appear in Quick Edit.
    if (!empty($data['tax_input'])) {
        foreach ($data['tax_input'] as $taxonomy => $terms) {
            $tax_object = get_taxonomy($taxonomy);
            /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
            if (!apply_filters('quick_edit_show_taxonomy', $tax_object->show_in_quick_edit, $taxonomy, $post['post_type'])) {
                unset($data['tax_input'][$taxonomy]);
            }
        }
    }
    // Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published.
    if (!empty($data['post_name']) && in_array($post['post_status'], array('draft', 'pending'))) {
        $post['post_status'] = 'publish';
        $data['post_name'] = wp_unique_post_slug($data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent']);
    }
    // Update the post.
    edit_post();
    $wp_list_table = _get_list_table('WP_Posts_List_Table', array('screen' => $_POST['screen']));
    $mode = $_POST['post_view'] === 'excerpt' ? 'excerpt' : 'list';
    $level = 0;
    $request_post = array(get_post($_POST['post_ID']));
    $parent = $request_post[0]->post_parent;
    while ($parent > 0) {
        $parent_post = get_post($parent);
        $parent = $parent_post->post_parent;
        $level++;
    }
    $wp_list_table->display_rows(array(get_post($_POST['post_ID'])), $level);
    wp_die();
}
Ejemplo n.º 25
0
function wp_ajax_inline_save()
{
    global $wp_list_table;
    check_ajax_referer('inlineeditnonce', '_inline_edit');
    if (!isset($_POST['post_ID']) || !($post_ID = (int) $_POST['post_ID'])) {
        wp_die();
    }
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_ID)) {
            wp_die(__('You are not allowed to edit this page.'));
        }
    } else {
        if (!current_user_can('edit_post', $post_ID)) {
            wp_die(__('You are not allowed to edit this post.'));
        }
    }
    if ($last = wp_check_post_lock($post_ID)) {
        $last_user = get_userdata($last);
        $last_user_name = $last_user ? $last_user->display_name : __('Someone');
        printf($_POST['post_type'] == 'page' ? __('Saving is disabled: %s is currently editing this page.') : __('Saving is disabled: %s is currently editing this post.'), esc_html($last_user_name));
        wp_die();
    }
    $data =& $_POST;
    $post = get_post($post_ID, ARRAY_A);
    $post = wp_slash($post);
    //since it is from db
    $data['content'] = $post['post_content'];
    $data['excerpt'] = $post['post_excerpt'];
    // rename
    $data['user_ID'] = get_current_user_id();
    if (isset($data['post_parent'])) {
        $data['parent_id'] = $data['post_parent'];
    }
    // Status.
    if (isset($data['keep_private']) && 'private' == $data['keep_private']) {
        $data['visibility'] = 'private';
        $data['post_status'] = 'private';
    } else {
        $data['post_status'] = $data['_status'];
    }
    if (empty($data['comment_status'])) {
        $data['comment_status'] = 'closed';
    }
    if (empty($data['ping_status'])) {
        $data['ping_status'] = 'closed';
    }
    // Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published.
    if (!empty($data['post_name']) && in_array($post['post_status'], array('draft', 'pending'))) {
        $post['post_status'] = 'publish';
        $data['post_name'] = wp_unique_post_slug($data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent']);
    }
    // update the post
    edit_post();
    $wp_list_table = _get_list_table('WP_Posts_List_Table', array('screen' => $_POST['screen']));
    $mode = $_POST['post_view'];
    $level = 0;
    $request_post = array(get_post($_POST['post_ID']));
    $parent = $request_post[0]->post_parent;
    while ($parent > 0) {
        $parent_post = get_post($parent);
        $parent = $parent_post->post_parent;
        $level++;
    }
    $wp_list_table->display_rows(array(get_post($_POST['post_ID'])), $level);
    wp_die();
}
Ejemplo n.º 26
0
/**
 * Checks if another user is editing an idea, if not
 * locks the idea for the current user.
 *
 * @package WP Idea Stream
 * @subpackage ideas/functions
 *
 * @since 2.0.0
 *
 * @param  int $idea_id The ID of the idea to edit
 * @uses   wp_check_post_lock() to check if the idea is locked to another user
 * @uses   wp_set_post_lock() to lock the idea to current user
 * @return int                the user id editing the idea
 */
function wp_idea_stream_ideas_lock_idea($idea_id = 0)
{
    $user_id = false;
    // Bail if no ID to check
    if (empty($idea_id)) {
        return $user_id;
    }
    // Include needed file
    require_once ABSPATH . '/wp-admin/includes/post.php';
    $user_id = wp_check_post_lock($idea_id);
    // If not locked, then lock it as current user is editing it.
    if (empty($user_id)) {
        wp_set_post_lock($idea_id);
    }
    return $user_id;
}
Ejemplo n.º 27
0
function wp_ajax_inline_save()
{
    global $wp_list_table;
    check_ajax_referer('inlineeditnonce', '_inline_edit');
    if (!isset($_POST['post_ID']) || !($post_ID = (int) $_POST['post_ID'])) {
        wp_die();
    }
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_ID)) {
            wp_die(__('You are not allowed to edit this page.'));
        }
    } else {
        if (!current_user_can('edit_post', $post_ID)) {
            wp_die(__('You are not allowed to edit this post.'));
        }
    }
    set_current_screen($_POST['screen']);
    if ($last = wp_check_post_lock($post_ID)) {
        $last_user = get_userdata($last);
        $last_user_name = $last_user ? $last_user->display_name : __('Someone');
        printf($_POST['post_type'] == 'page' ? __('Saving is disabled: %s is currently editing this page.') : __('Saving is disabled: %s is currently editing this post.'), esc_html($last_user_name));
        wp_die();
    }
    $data =& $_POST;
    $post = get_post($post_ID, ARRAY_A);
    $post = add_magic_quotes($post);
    //since it is from db
    $data['content'] = $post['post_content'];
    $data['excerpt'] = $post['post_excerpt'];
    // rename
    $data['user_ID'] = $GLOBALS['user_ID'];
    if (isset($data['post_parent'])) {
        $data['parent_id'] = $data['post_parent'];
    }
    // status
    if (isset($data['keep_private']) && 'private' == $data['keep_private']) {
        $data['post_status'] = 'private';
    } else {
        $data['post_status'] = $data['_status'];
    }
    if (empty($data['comment_status'])) {
        $data['comment_status'] = 'closed';
    }
    if (empty($data['ping_status'])) {
        $data['ping_status'] = 'closed';
    }
    // update the post
    edit_post();
    $wp_list_table = _get_list_table('WP_Posts_List_Table');
    $mode = $_POST['post_view'];
    $wp_list_table->display_rows(array(get_post($_POST['post_ID'])));
    wp_die();
}
Ejemplo n.º 28
0
 /**
  * Handle spam/unspam bulk actions.
  *
  * @since 2.6.0 bbPress (r6101)
  *
  * @param string $sendback The sendback URL.
  * @param string $doaction The action to be taken.
  * @param array  $post_ids The post IDS to take the action on.
  * @return string The sendback URL.
  */
 public function handle_bulk_actions($sendback, $doaction, $post_ids)
 {
     if ($this->bail()) {
         return $sendback;
     }
     $sendback = remove_query_arg(array('spam', 'unspam'), $sendback);
     $updated = $locked = 0;
     if ('spam' === $doaction) {
         foreach ((array) $post_ids as $post_id) {
             if (!current_user_can('moderate', $post_id)) {
                 wp_die(__('Sorry, you are not allowed to spam this item.', 'bbpress'));
             }
             if (wp_check_post_lock($post_id)) {
                 $locked++;
                 continue;
             }
             if (!bbp_spam_reply($post_id)) {
                 wp_die(__('Error in spamming reply.', 'bbpress'));
             }
             $updated++;
         }
         $sendback = add_query_arg(array('updated' => $updated, 'ids' => join(',', $post_ids), 'locked' => $locked), $sendback);
     } elseif ('unspam' === $doaction) {
         foreach ((array) $post_ids as $post_id) {
             if (!current_user_can('moderate', $post_id)) {
                 wp_die(__('Sorry, you are not allowed to unspam this reply.', 'bbpress'));
             }
             if (wp_check_post_lock($post_id)) {
                 $locked++;
                 continue;
             }
             if (!bbp_unspam_reply($post_id)) {
                 wp_die(__('Error in unspamming reply.', 'bbpress'));
             }
             $updated++;
         }
         $sendback = add_query_arg(array('updated' => $updated, 'ids' => join(',', $post_ids), 'locked' => $locked), $sendback);
     }
     return $sendback;
 }
Ejemplo n.º 29
0
    /**
     * @global WP_Post $post
     *
     * @param int|WP_Post $post
     * @param int         $level
     */
    public function single_row($post, $level = 0)
    {
        $global_post = get_post();
        $post = get_post($post);
        $this->current_level = $level;
        $GLOBALS['post'] = $post;
        setup_postdata($post);
        $classes = 'iedit author-' . (get_current_user_id() == $post->post_author ? 'self' : 'other');
        $lock_holder = wp_check_post_lock($post->ID);
        if ($lock_holder) {
            $classes .= ' wp-locked';
        }
        if ($post->post_parent) {
            $count = count(get_post_ancestors($post->ID));
            $classes .= ' level-' . $count;
        } else {
            $classes .= ' level-0';
        }
        ?>
		<tr id="post-<?php 
        echo $post->ID;
        ?>
" class="<?php 
        echo implode(' ', get_post_class($classes, $post->ID));
        ?>
">
			<?php 
        $this->single_row_columns($post);
        ?>
		</tr>
	<?php 
        $GLOBALS['post'] = $global_post;
    }
Ejemplo n.º 30
0
				<div class="author-info">
				<# if ( data.attributes.autosave ) { #>
					<span class="byline"><?php printf( __( 'Autosave by %s' ),
						'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
				<# } else if ( data.attributes.current ) { #>
					<span class="byline"><?php printf( __( 'Current Revision by %s' ),
						'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
				<# } else { #>
					<span class="byline"><?php printf( __( 'Revision by %s' ),
						'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
				<# } #>
					<span class="time-ago">{{ data.attributes.timeAgo }}</span>
					<span class="date">({{ data.attributes.dateShort }})</span>
				</div>
			<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
				<input  <?php if ( wp_check_post_lock( $post->ID ) ) { ?>
					disabled="disabled"
				<?php } else { ?>
					<# if ( data.attributes.current ) { #>
						disabled="disabled"
					<# } #>
				<?php } ?>
				<# if ( data.attributes.autosave ) { #>
					type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" />
				<# } else { #>
					type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
				<# } #>
			<# } #>
		</div>
	<# if ( 'tooltip' === data.type ) { #>
		<div class="revisions-tooltip-arrow"><span></span></div>