Example #1
1
/**
 * Save draft or manually autosave for showing preview.
 *
 * @package WordPress
 * @since 2.7.0
 *
 * @return str URL to redirect to show the preview
 */
function post_preview()
{
    $post_ID = (int) $_POST['post_ID'];
    $_POST['ID'] = $post_ID;
    if (!($post = get_post($post_ID))) {
        wp_die(__('Sorry, you are not allowed to edit this post.'));
    }
    if (!current_user_can('edit_post', $post->ID)) {
        wp_die(__('Sorry, you are not allowed to edit this post.'));
    }
    $is_autosave = false;
    if (!wp_check_post_lock($post->ID) && get_current_user_id() == $post->post_author && ('draft' == $post->post_status || 'auto-draft' == $post->post_status)) {
        $saved_post_id = edit_post();
    } else {
        $is_autosave = true;
        if (isset($_POST['post_status']) && 'auto-draft' == $_POST['post_status']) {
            $_POST['post_status'] = 'draft';
        }
        $saved_post_id = wp_create_post_autosave($post->ID);
    }
    if (is_wp_error($saved_post_id)) {
        wp_die($saved_post_id->get_error_message());
    }
    $query_args = array();
    if ($is_autosave && $saved_post_id) {
        $query_args['preview_id'] = $post->ID;
        $query_args['preview_nonce'] = wp_create_nonce('post_preview_' . $post->ID);
        if (isset($_POST['post_format'])) {
            $query_args['post_format'] = empty($_POST['post_format']) ? 'standard' : sanitize_key($_POST['post_format']);
        }
        if (isset($_POST['_thumbnail_id'])) {
            $query_args['_thumbnail_id'] = intval($_POST['_thumbnail_id']) <= 0 ? '-1' : intval($_POST['_thumbnail_id']);
        }
    }
    return get_preview_post_link($post, $query_args);
}
Example #2
0
function wpnt_add_new_tab_link($actions, $page_object)
{
    global $post;
    if (in_array($post->post_status, array('pending', 'draft', 'future'))) {
        $unpublished_link = set_url_scheme(get_permalink($post));
        $preview_link = get_preview_post_link($post, array(), $unpublished_link);
        $actions['view_new_tab'] = '<a href="' . esc_url($preview_link) . '" rel="permalink" target="_blank">' . __('Preview In New Tab') . '</a>';
    } elseif ('trash' != $post->post_status) {
        $actions['view_new_tab'] = '<a href="' . get_permalink($post->ID) . '" rel="permalink" target="_blank">' . __('View In New Tab') . '</a>';
    }
    return $actions;
}
Example #3
0
/**
 * Ajax handler to retrieve a permalink.
 *
 * @since 3.1.0
 */
function wp_ajax_get_permalink()
{
    check_ajax_referer('getpermalink', 'getpermalinknonce');
    $post_id = isset($_POST['post_id']) ? intval($_POST['post_id']) : 0;
    wp_die(get_preview_post_link($post_id));
}
/**
 * Helper function for wp_link_pages().
 *
 * @since 3.1.0
 * @access private
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param int $i Page number.
 * @return string Link.
 */
function _wp_link_page($i)
{
    global $wp_rewrite;
    $post = get_post();
    $query_args = array();
    if (1 == $i) {
        $url = get_permalink();
    } else {
        if ('' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending'))) {
            $url = add_query_arg('page', $i, get_permalink());
        } elseif ('page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID) {
            $url = trailingslashit(get_permalink()) . user_trailingslashit("{$wp_rewrite->pagination_base}/" . $i, 'single_paged');
        } else {
            $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged');
        }
    }
    if (is_preview()) {
        if ('draft' !== $post->post_status && isset($_GET['preview_id'], $_GET['preview_nonce'])) {
            $query_args['preview_id'] = wp_unslash($_GET['preview_id']);
            $query_args['preview_nonce'] = wp_unslash($_GET['preview_nonce']);
        }
        $url = get_preview_post_link($post, $query_args, $url);
    }
    return '<a href="' . esc_url($url) . '">';
}
 /**
  * Generates and displays row action links.
  *
  * @since 4.3.0
  * @access protected
  *
  * @param object $post        Post being acted upon.
  * @param string $column_name Current column name.
  * @param string $primary     Primary column name.
  * @return string Row actions output for posts.
  */
 protected function handle_row_actions($post, $column_name, $primary)
 {
     if ($primary !== $column_name) {
         return '';
     }
     $post_type_object = get_post_type_object($post->post_type);
     $can_edit_post = current_user_can('edit_post', $post->ID);
     $actions = array();
     $title = _draft_or_post_title();
     if ($can_edit_post && 'trash' != $post->post_status) {
         $actions['edit'] = sprintf('<a href="%s" aria-label="%s">%s</a>', get_edit_post_link($post->ID), esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)), __('Edit'));
         $actions['inline hide-if-no-js'] = sprintf('<a href="#" class="editinline" aria-label="%s">%s</a>', esc_attr(sprintf(__('Quick edit &#8220;%s&#8221; inline'), $title)), __('Quick&nbsp;Edit'));
     }
     if (current_user_can('delete_post', $post->ID)) {
         if ('trash' === $post->post_status) {
             $actions['untrash'] = sprintf('<a href="%s" aria-label="%s">%s</a>', wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&amp;action=untrash', $post->ID)), 'untrash-post_' . $post->ID), esc_attr(sprintf(__('Restore &#8220;%s&#8221; from the Trash'), $title)), __('Restore'));
         } elseif (EMPTY_TRASH_DAYS) {
             $actions['trash'] = sprintf('<a href="%s" class="submitdelete" aria-label="%s">%s</a>', get_delete_post_link($post->ID), esc_attr(sprintf(__('Move &#8220;%s&#8221; to the Trash'), $title)), _x('Trash', 'verb'));
         }
         if ('trash' === $post->post_status || !EMPTY_TRASH_DAYS) {
             $actions['delete'] = sprintf('<a href="%s" class="submitdelete" aria-label="%s">%s</a>', get_delete_post_link($post->ID, '', true), esc_attr(sprintf(__('Delete &#8220;%s&#8221; permanently'), $title)), __('Delete Permanently'));
         }
     }
     if (is_post_type_viewable($post_type_object)) {
         if (in_array($post->post_status, array('pending', 'draft', 'future'))) {
             if ($can_edit_post) {
                 $unpublished_link = set_url_scheme(get_permalink($post));
                 $preview_link = get_preview_post_link($post, array(), $unpublished_link);
                 $actions['view'] = sprintf('<a href="%s" rel="permalink" aria-label="%s">%s</a>', esc_url($preview_link), esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)), __('Preview'));
             }
         } elseif ('trash' != $post->post_status) {
             $actions['view'] = sprintf('<a href="%s" rel="permalink" aria-label="%s">%s</a>', get_permalink($post->ID), esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)), __('View'));
         }
     }
     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('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('post_row_actions', $actions, $post);
     }
     return $this->row_actions($actions);
 }
Example #6
0
/**
 * Displays post submit form fields.
 *
 * @since 2.7.0
 *
 * @global string $action
 *
 * @param WP_Post  $post Current post object.
 * @param array    $args {
 *     Array of arguments for building the post submit meta box.
 *
 *     @type string   $id       Meta box ID.
 *     @type string   $title    Meta box title.
 *     @type callable $callback Meta box display callback.
 *     @type array    $args     Extra meta box arguments.
 * }
 */
function post_submit_meta_box($post, $args = array())
{
    global $action;
    $post_type = $post->post_type;
    $post_type_object = get_post_type_object($post_type);
    $can_publish = current_user_can($post_type_object->cap->publish_posts);
    ?>
<div class="submitbox" id="submitpost">

<div id="minor-publishing">

<?php 
    // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key
    ?>
<div style="display:none;">
<?php 
    submit_button(__('Save'), 'button', 'save');
    ?>
</div>

<div id="minor-publishing-actions">
<div id="save-action">
<?php 
    if ('publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status) {
        ?>
<input <?php 
        if ('private' == $post->post_status) {
            ?>
style="display:none"<?php 
        }
        ?>
 type="submit" name="save" id="save-post" value="<?php 
        esc_attr_e('Save Draft');
        ?>
" class="button" />
<span class="spinner"></span>
<?php 
    } elseif ('pending' == $post->post_status && $can_publish) {
        ?>
<input type="submit" name="save" id="save-post" value="<?php 
        esc_attr_e('Save as Pending');
        ?>
" class="button" />
<span class="spinner"></span>
<?php 
    }
    ?>
</div>
<?php 
    if (is_post_type_viewable($post_type_object)) {
        ?>
<div id="preview-action">
<?php 
        $preview_link = esc_url(get_preview_post_link($post));
        if ('publish' == $post->post_status) {
            $preview_button = __('Preview Changes');
        } else {
            $preview_button = __('Preview');
        }
        ?>
<a class="preview button" href="<?php 
        echo $preview_link;
        ?>
" target="wp-preview-<?php 
        echo (int) $post->ID;
        ?>
" id="post-preview"><?php 
        echo $preview_button;
        ?>
</a>
<input type="hidden" name="wp-preview" id="wp-preview" value="" />
</div>
<?php 
    }
    // public post type
    /**
     * Fires before the post time/date setting in the Publish meta box.
     *
     * @since 4.4.0
     *
     * @param WP_Post $post WP_Post object for the current post.
     */
    do_action('post_submitbox_minor_actions', $post);
    ?>
<div class="clear"></div>
</div><!-- #minor-publishing-actions -->

<div id="misc-publishing-actions">

<div class="misc-pub-section misc-pub-post-status"><label for="post_status"><?php 
    _e('Status:');
    ?>
</label>
<span id="post-status-display">
<?php 
    switch ($post->post_status) {
        case 'private':
            _e('Privately Published');
            break;
        case 'publish':
            _e('Published');
            break;
        case 'future':
            _e('Scheduled');
            break;
        case 'pending':
            _e('Pending Review');
            break;
        case 'draft':
        case 'auto-draft':
            _e('Draft');
            break;
    }
    ?>
</span>
<?php 
    if ('publish' == $post->post_status || 'private' == $post->post_status || $can_publish) {
        ?>
<a href="#post_status" <?php 
        if ('private' == $post->post_status) {
            ?>
style="display:none;" <?php 
        }
        ?>
class="edit-post-status hide-if-no-js"><span aria-hidden="true"><?php 
        _e('Edit');
        ?>
</span> <span class="screen-reader-text"><?php 
        _e('Edit status');
        ?>
</span></a>

<div id="post-status-select" class="hide-if-js">
<input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php 
        echo esc_attr('auto-draft' == $post->post_status ? 'draft' : $post->post_status);
        ?>
" />
<select name='post_status' id='post_status'>
<?php 
        if ('publish' == $post->post_status) {
            ?>
<option<?php 
            selected($post->post_status, 'publish');
            ?>
 value='publish'><?php 
            _e('Published');
            ?>
</option>
<?php 
        } elseif ('private' == $post->post_status) {
            ?>
<option<?php 
            selected($post->post_status, 'private');
            ?>
 value='publish'><?php 
            _e('Privately Published');
            ?>
</option>
<?php 
        } elseif ('future' == $post->post_status) {
            ?>
<option<?php 
            selected($post->post_status, 'future');
            ?>
 value='future'><?php 
            _e('Scheduled');
            ?>
</option>
<?php 
        }
        ?>
<option<?php 
        selected($post->post_status, 'pending');
        ?>
 value='pending'><?php 
        _e('Pending Review');
        ?>
</option>
<?php 
        if ('auto-draft' == $post->post_status) {
            ?>
<option<?php 
            selected($post->post_status, 'auto-draft');
            ?>
 value='draft'><?php 
            _e('Draft');
            ?>
</option>
<?php 
        } else {
            ?>
<option<?php 
            selected($post->post_status, 'draft');
            ?>
 value='draft'><?php 
            _e('Draft');
            ?>
</option>
<?php 
        }
        ?>
</select>
 <a href="#post_status" class="save-post-status hide-if-no-js button"><?php 
        _e('OK');
        ?>
</a>
 <a href="#post_status" class="cancel-post-status hide-if-no-js button-cancel"><?php 
        _e('Cancel');
        ?>
</a>
</div>

<?php 
    }
    ?>
</div><!-- .misc-pub-section -->

<div class="misc-pub-section misc-pub-visibility" id="visibility">
<?php 
    _e('Visibility:');
    ?>
 <span id="post-visibility-display"><?php 
    if ('private' == $post->post_status) {
        $post->post_password = '';
        $visibility = 'private';
        $visibility_trans = __('Private');
    } elseif (!empty($post->post_password)) {
        $visibility = 'password';
        $visibility_trans = __('Password protected');
    } elseif ($post_type == 'post' && is_sticky($post->ID)) {
        $visibility = 'public';
        $visibility_trans = __('Public, Sticky');
    } else {
        $visibility = 'public';
        $visibility_trans = __('Public');
    }
    echo esc_html($visibility_trans);
    ?>
</span>
<?php 
    if ($can_publish) {
        ?>
<a href="#visibility" class="edit-visibility hide-if-no-js"><span aria-hidden="true"><?php 
        _e('Edit');
        ?>
</span> <span class="screen-reader-text"><?php 
        _e('Edit visibility');
        ?>
</span></a>

<div id="post-visibility-select" class="hide-if-js">
<input type="hidden" name="hidden_post_password" id="hidden-post-password" value="<?php 
        echo esc_attr($post->post_password);
        ?>
" />
<?php 
        if ($post_type == 'post') {
            ?>
<input type="checkbox" style="display:none" name="hidden_post_sticky" id="hidden-post-sticky" value="sticky" <?php 
            checked(is_sticky($post->ID));
            ?>
 />
<?php 
        }
        ?>
<input type="hidden" name="hidden_post_visibility" id="hidden-post-visibility" value="<?php 
        echo esc_attr($visibility);
        ?>
" />
<input type="radio" name="visibility" id="visibility-radio-public" value="public" <?php 
        checked($visibility, 'public');
        ?>
 /> <label for="visibility-radio-public" class="selectit"><?php 
        _e('Public');
        ?>
</label><br />
<?php 
        if ($post_type == 'post' && current_user_can('edit_others_posts')) {
            ?>
<span id="sticky-span"><input id="sticky" name="sticky" type="checkbox" value="sticky" <?php 
            checked(is_sticky($post->ID));
            ?>
 /> <label for="sticky" class="selectit"><?php 
            _e('Stick this post to the front page');
            ?>
</label><br /></span>
<?php 
        }
        ?>
<input type="radio" name="visibility" id="visibility-radio-password" value="password" <?php 
        checked($visibility, 'password');
        ?>
 /> <label for="visibility-radio-password" class="selectit"><?php 
        _e('Password protected');
        ?>
</label><br />
<span id="password-span"><label for="post_password"><?php 
        _e('Password:'******'private');
        ?>
 /> <label for="visibility-radio-private" class="selectit"><?php 
        _e('Private');
        ?>
</label><br />

<p>
 <a href="#visibility" class="save-post-visibility hide-if-no-js button"><?php 
        _e('OK');
        ?>
</a>
 <a href="#visibility" class="cancel-post-visibility hide-if-no-js button-cancel"><?php 
        _e('Cancel');
        ?>
</a>
</p>
</div>
<?php 
    }
    ?>

</div><!-- .misc-pub-section -->

<?php 
    /* translators: Publish box date format, see http://php.net/date */
    $datef = __('M j, Y @ H:i');
    if (0 != $post->ID) {
        if ('future' == $post->post_status) {
            // scheduled for publishing at a future date
            $stamp = __('Scheduled for: <b>%1$s</b>');
        } elseif ('publish' == $post->post_status || 'private' == $post->post_status) {
            // already published
            $stamp = __('Published on: <b>%1$s</b>');
        } elseif ('0000-00-00 00:00:00' == $post->post_date_gmt) {
            // draft, 1 or more saves, no date specified
            $stamp = __('Publish <b>immediately</b>');
        } elseif (time() < strtotime($post->post_date_gmt . ' +0000')) {
            // draft, 1 or more saves, future date specified
            $stamp = __('Schedule for: <b>%1$s</b>');
        } else {
            // draft, 1 or more saves, date specified
            $stamp = __('Publish on: <b>%1$s</b>');
        }
        $date = date_i18n($datef, strtotime($post->post_date));
    } else {
        // draft (no saves, and thus no date specified)
        $stamp = __('Publish <b>immediately</b>');
        $date = date_i18n($datef, strtotime(current_time('mysql')));
    }
    if (!empty($args['args']['revisions_count'])) {
        $revisions_to_keep = wp_revisions_to_keep($post);
        ?>
<div class="misc-pub-section misc-pub-revisions">
<?php 
        if ($revisions_to_keep > 0 && $revisions_to_keep <= $args['args']['revisions_count']) {
            echo '<span title="' . esc_attr(sprintf(__('Your site is configured to keep only the last %s revisions.'), number_format_i18n($revisions_to_keep))) . '">';
            printf(__('Revisions: %s'), '<b>' . number_format_i18n($args['args']['revisions_count']) . '+</b>');
            echo '</span>';
        } else {
            printf(__('Revisions: %s'), '<b>' . number_format_i18n($args['args']['revisions_count']) . '</b>');
        }
        ?>
	<a class="hide-if-no-js" href="<?php 
        echo esc_url(get_edit_post_link($args['args']['revision_id']));
        ?>
"><span aria-hidden="true"><?php 
        _ex('Browse', 'revisions');
        ?>
</span> <span class="screen-reader-text"><?php 
        _e('Browse revisions');
        ?>
</span></a>
</div>
<?php 
    }
    if ($can_publish) {
        // Contributors don't get to choose the date of publish
        ?>
<div class="misc-pub-section curtime misc-pub-curtime">
	<span id="timestamp">
	<?php 
        printf($stamp, $date);
        ?>
</span>
	<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js"><span aria-hidden="true"><?php 
        _e('Edit');
        ?>
</span> <span class="screen-reader-text"><?php 
        _e('Edit date and time');
        ?>
</span></a>
	<fieldset id="timestampdiv" class="hide-if-js">
	<legend class="screen-reader-text"><?php 
        _e('Date and time');
        ?>
</legend>
	<?php 
        touch_time($action === 'edit', 1);
        ?>
	</fieldset>
</div><?php 
        // /misc-pub-section
    }
    ?>

<?php 
    /**
     * Fires after the post time/date setting in the Publish meta box.
     *
     * @since 2.9.0
     * @since 4.4.0 Added the `$post` parameter.
     *
     * @param WP_Post $post WP_Post object for the current post.
     */
    do_action('post_submitbox_misc_actions', $post);
    ?>
</div>
<div class="clear"></div>
</div>

<div id="major-publishing-actions">
<?php 
    /**
     * Fires at the beginning of the publishing actions section of the Publish meta box.
     *
     * @since 2.7.0
     */
    do_action('post_submitbox_start');
    ?>
<div id="delete-action">
<?php 
    if (current_user_can("delete_post", $post->ID)) {
        if (!EMPTY_TRASH_DAYS) {
            $delete_text = __('Delete Permanently');
        } else {
            $delete_text = __('Move to Trash');
        }
        ?>
<a class="submitdelete deletion" href="<?php 
        echo get_delete_post_link($post->ID);
        ?>
"><?php 
        echo $delete_text;
        ?>
</a><?php 
    }
    ?>
</div>

<div id="publishing-action">
<span class="spinner"></span>
<?php 
    if (!in_array($post->post_status, array('publish', 'future', 'private')) || 0 == $post->ID) {
        if ($can_publish) {
            if (!empty($post->post_date_gmt) && time() < strtotime($post->post_date_gmt . ' +0000')) {
                ?>
		<input name="original_publish" type="hidden" id="original_publish" value="<?php 
                esc_attr_e('Schedule');
                ?>
" />
		<?php 
                submit_button(__('Schedule'), 'primary button-large', 'publish', false);
            } else {
                ?>
		<input name="original_publish" type="hidden" id="original_publish" value="<?php 
                esc_attr_e('Publish');
                ?>
" />
		<?php 
                submit_button(__('Publish'), 'primary button-large', 'publish', false);
            }
        } else {
            ?>
		<input name="original_publish" type="hidden" id="original_publish" value="<?php 
            esc_attr_e('Submit for Review');
            ?>
" />
		<?php 
            submit_button(__('Submit for Review'), 'primary button-large', 'publish', false);
        }
    } else {
        ?>
		<input name="original_publish" type="hidden" id="original_publish" value="<?php 
        esc_attr_e('Update');
        ?>
" />
		<input name="save" type="submit" class="button button-primary button-large" id="publish" value="<?php 
        esc_attr_e('Update');
        ?>
" />
<?php 
    }
    ?>
</div>
<div class="clear"></div>
</div>
</div>

<?php 
}
    add_thickbox();
    wp_enqueue_media(array('post' => $post_ID));
}
// Add the local autosave notice HTML
add_action('admin_footer', '_local_storage_notice');
/*
 * @todo Document the $messages array(s).
 */
$permalink = get_permalink($post_ID);
if (!$permalink) {
    $permalink = '';
}
$messages = array();
$preview_post_link_html = $scheduled_post_link_html = $view_post_link_html = '';
$preview_page_link_html = $scheduled_page_link_html = $view_page_link_html = '';
$preview_url = get_preview_post_link($post);
$viewable = is_post_type_viewable($post_type_object);
if ($viewable) {
    // Preview post link.
    $preview_post_link_html = sprintf(' <a target="_blank" href="%1$s">%2$s</a>', esc_url($preview_url), __('Preview post'));
    // Scheduled post preview link.
    $scheduled_post_link_html = sprintf(' <a target="_blank" href="%1$s">%2$s</a>', esc_url($permalink), __('Preview post'));
    // View post link.
    $view_post_link_html = sprintf(' <a href="%1$s">%2$s</a>', esc_url($permalink), __('View post'));
    // Preview page link.
    $preview_page_link_html = sprintf(' <a target="_blank" href="%1$s">%2$s</a>', esc_url($preview_url), __('Preview page'));
    // Scheduled page preview link.
    $scheduled_page_link_html = sprintf(' <a target="_blank" href="%1$s">%2$s</a>', esc_url($permalink), __('Preview page'));
    // View page link.
    $view_page_link_html = sprintf(' <a href="%1$s">%2$s</a>', esc_url($permalink), __('View page'));
}
Example #8
0
/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @global WP_Term  $tag
 * @global WP_Query $wp_the_query
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $post = get_post();
        if ('post' == $current_screen->base && 'add' != $current_screen->action && ($post_type_object = get_post_type_object($post->post_type)) && current_user_can('read_post', $post->ID) && $post_type_object->public && $post_type_object->show_in_admin_bar) {
            if ('draft' == $post->post_status) {
                $preview_link = get_preview_post_link($post);
                $wp_admin_bar->add_menu(array('id' => 'preview', 'title' => $post_type_object->labels->view_item, 'href' => esc_url($preview_link), 'meta' => array('target' => 'wp-preview-' . $post->ID)));
            } else {
                $wp_admin_bar->add_menu(array('id' => 'view', 'title' => $post_type_object->labels->view_item, 'href' => get_permalink($post->ID)));
            }
        } elseif ('term' == $current_screen->base && isset($tag) && is_object($tag) && !is_wp_error($tag) && ($tax = get_taxonomy($tag->taxonomy)) && $tax->public) {
            $wp_admin_bar->add_menu(array('id' => 'view', 'title' => $tax->labels->view_item, 'href' => get_term_link($tag)));
        }
    } else {
        $current_object = $wp_the_query->get_queried_object();
        if (empty($current_object)) {
            return;
        }
        if (!empty($current_object->post_type) && ($post_type_object = get_post_type_object($current_object->post_type)) && current_user_can('edit_post', $current_object->ID) && $post_type_object->show_in_admin_bar && ($edit_post_link = get_edit_post_link($current_object->ID))) {
            $wp_admin_bar->add_menu(array('id' => 'edit', 'title' => $post_type_object->labels->edit_item, 'href' => $edit_post_link));
        } elseif (!empty($current_object->taxonomy) && ($tax = get_taxonomy($current_object->taxonomy)) && current_user_can($tax->cap->edit_terms) && ($edit_term_link = get_edit_term_link($current_object->term_id, $current_object->taxonomy))) {
            $wp_admin_bar->add_menu(array('id' => 'edit', 'title' => $tax->labels->edit_item, 'href' => $edit_term_link));
        }
    }
}
/**
 * Adds custom post updated messages on the edit post screen.
 *
 * @since  1.0.0
 * @access public
 * @param  array  $messages
 * @global object $post
 * @global int    $post_ID
 * @return array
 */
function ccp_post_updated_messages($messages)
{
    global $post, $post_ID;
    $project_type = ccp_get_project_post_type();
    if ($project_type !== $post->post_type) {
        return $messages;
    }
    // Get permalink and preview URLs.
    $permalink = get_permalink($post_ID);
    $preview_url = function_exists('get_preview_post_link') ? get_preview_post_link($post) : apply_filters('preview_post_link', add_query_arg(array('preview' => true), $permalink), $post);
    // Translators: Scheduled project date format. See http://php.net/date
    $scheduled_date = date_i18n(__('M j, Y @ H:i', 'custom-content-portfolio'), strtotime($post->post_date));
    // Set up view links.
    $preview_link = sprintf(' <a target="_blank" href="%1$s">%2$s</a>', esc_url($preview_url), esc_html__('Preview project', 'custom-content-portfolio'));
    $scheduled_link = sprintf(' <a target="_blank" href="%1$s">%2$s</a>', esc_url($permalink), esc_html__('Preview project', 'custom-content-portfolio'));
    $view_link = sprintf(' <a href="%1$s">%2$s</a>', esc_url($permalink), esc_html__('View project', 'custom-content-portfolio'));
    // Post updated messages.
    $messages[$project_type] = array(1 => esc_html__('Project updated.', 'custom-content-portfolio') . $view_link, 4 => esc_html__('Project updated.', 'custom-content-portfolio'), 5 => isset($_GET['revision']) ? sprintf(esc_html__('Project restored to revision from %s.', 'custom-content-portfolio'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => esc_html__('Project published.', 'custom-content-portfolio') . $view_link, 7 => esc_html__('Project saved.', 'custom-content-portfolio'), 8 => esc_html__('Project submitted.', 'custom-content-portfolio') . $preview_link, 9 => sprintf(esc_html__('Project scheduled for: %s.', 'custom-content-portfolio'), "<strong>{$scheduled_date}</strong>") . $scheduled_link, 10 => esc_html__('Project draft updated.', 'custom-content-portfolio') . $preview_link);
    return $messages;
}
 /**
  * @ticket 30910
  * @ticket 18306
  */
 public function test_get_sample_permalink_html_should_use_preview_links_for_draft_and_pending_posts_with_no_post_name()
 {
     $this->set_permalink_structure('/%postname%/');
     wp_set_current_user(self::$admin_id);
     $future_date = date('Y-m-d H:i:s', time() + 100);
     $p = self::factory()->post->create(array('post_status' => 'pending', 'post_name' => '', 'post_date' => $future_date));
     $found = get_sample_permalink_html($p);
     $post = get_post($p);
     $this->assertContains('href="' . esc_url(get_preview_post_link($post)), $found);
 }
 public function test_get_preview_post_link_should_return_empty_string_for_non_viewable_post_type()
 {
     $post_type = register_post_type(rand_str(12), array('public' => false));
     $post = self::factory()->post->create(array('post_type' => $post_type->name));
     $this->assertSame('', get_preview_post_link($post));
 }
Example #12
0
/**
 * Adds custom post updated messages on the edit post screen.
 *
 * @since  1.0.0
 * @access public
 * @param  array  $messages
 * @global object $post
 * @global int    $post_ID
 * @return array
 */
function thds_post_updated_messages($messages)
{
    global $post, $post_ID;
    $theme_type = thds_get_theme_post_type();
    if ($theme_type !== $post->post_type) {
        return $messages;
    }
    // Get permalink and preview URLs.
    $permalink = get_permalink($post_ID);
    $preview_url = get_preview_post_link($post);
    // Translators: Scheduled theme date format. See http://php.net/date
    $scheduled_date = date_i18n(__('M j, Y @ H:i', 'theme-designer'), strtotime($post->post_date));
    // Set up view links.
    $preview_link = sprintf(' <a target="_blank" href="%1$s">%2$s</a>', esc_url($preview_url), esc_html__('Preview theme', 'theme-designer'));
    $scheduled_link = sprintf(' <a target="_blank" href="%1$s">%2$s</a>', esc_url($permalink), esc_html__('Preview theme', 'theme-designer'));
    $view_link = sprintf(' <a href="%1$s">%2$s</a>', esc_url($permalink), esc_html__('View theme', 'theme-designer'));
    // Post updated messages.
    $messages[$theme_type] = array(1 => esc_html__('Theme updated.', 'theme-designer') . $view_link, 4 => esc_html__('Theme updated.', 'theme-designer'), 5 => isset($_GET['revision']) ? sprintf(esc_html__('Theme restored to revision from %s.', 'theme-designer'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => esc_html__('Theme published.', 'theme-designer') . $view_link, 7 => esc_html__('Theme saved.', 'theme-designer'), 8 => esc_html__('Theme submitted.', 'theme-designer') . $preview_link, 9 => sprintf(esc_html__('Theme scheduled for: %s.', 'theme-designer'), "<strong>{$scheduled_date}</strong>") . $scheduled_link, 10 => esc_html__('Theme draft updated.', 'theme-designer') . $preview_link);
    return $messages;
}
Example #13
0
 /**
  * Output column data for a Posts 2 Posts connection.
  *
  * @param string $connection The ID of the connection type
  * @param array  $args       Optional. Array of arguments for a given connection type
  */
 public function col_connection($connection, array $args = array())
 {
     global $post, $wp_query;
     if (!function_exists('p2p_type')) {
         return;
     }
     if (!$this->p2p_connection_exists($connection)) {
         echo esc_html(sprintf(__('Invalid connection type: %s', 'extended-cpts'), $connection));
         return;
     }
     $_post = $post;
     $meta = $out = array();
     $field = 'connected_' . $connection;
     if (isset($args['field']) && isset($args['value'])) {
         $meta = array('connected_meta' => array($args['field'] => $args['value']));
         $field .= sanitize_title('_' . $args['field'] . '_' . $args['value']);
     }
     if (!isset($_post->{$field})) {
         if ($type = p2p_type($connection)) {
             $type->each_connected($wp_query, $meta, $field);
         } else {
             echo esc_html(sprintf(__('Invalid connection type: %s', 'extended-cpts'), $connection));
             return;
         }
     }
     foreach ($_post->{$field} as $post) {
         setup_postdata($post);
         $pto = get_post_type_object($post->post_type);
         $pso = get_post_status_object($post->post_status);
         if ($pso->protected && !current_user_can('edit_post', $post->ID)) {
             continue;
         }
         if ('trash' == $post->post_status) {
             continue;
         }
         if ($args['link']) {
             switch ($args['link']) {
                 case 'view':
                     if ($pto->public) {
                         if ($pso->protected) {
                             $out[] = sprintf('<a href="%1$s">%2$s</a>', esc_url(get_preview_post_link()), esc_html(get_the_title()));
                         } else {
                             $out[] = sprintf('<a href="%1$s">%2$s</a>', esc_url(get_permalink()), esc_html(get_the_title()));
                         }
                     } else {
                         $out[] = esc_html(get_the_title());
                     }
                     break;
                 case 'edit':
                     if (current_user_can('edit_post', $post->ID)) {
                         $out[] = sprintf('<a href="%1$s">%2$s</a>', esc_url(get_edit_post_link()), esc_html(get_the_title()));
                     } else {
                         $out[] = esc_html(get_the_title());
                     }
                     break;
                 case 'list':
                     $link = add_query_arg(array_merge(array('post_type' => $_post->post_type, 'connected_type' => $connection, 'connected_items' => $post->ID), $meta), admin_url('edit.php'));
                     $out[] = sprintf('<a href="%1$s">%2$s</a>', esc_url($link), esc_html(get_the_title()));
                     break;
             }
         } else {
             $out[] = esc_html(get_the_title());
         }
     }
     $post = $_post;
     // WPCS: override ok.
     echo implode(', ', $out);
     // WPCS: XSS ok.
 }