<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[3655] sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/showcase/rosetta-showcase.php: Rosetta Showcase: Move logic into a class so it can be initialized only when needed.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/3655">3655</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/3655","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ocean90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-07-08 23:20:21 +0000 (Fri, 08 Jul 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Rosetta Showcase: Move logic into a class so it can be initialized only when needed.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsshowcaserosettashowcasephp">sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/showcase/rosetta-showcase.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsshowcaserosettashowcasephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/showcase/rosetta-showcase.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/showcase/rosetta-showcase.php 2016-07-08 18:59:17 UTC (rev 3654)
+++ sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/showcase/rosetta-showcase.php 2016-07-08 23:20:21 UTC (rev 3655)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,147 +1,255 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/*
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Plugin Name: Rosetta Showcase
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Plugin URI: https://wordpress.org/
+ * Description: Showcase for local sites.
</ins><span class="cx" style="display: block; padding: 0 10px"> * Author: Zé Fontainhas and Andrew Nacin
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Version: 2.0
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Rosetta_Showcase {
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_action( 'init', 'rosetta_showcase_register' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Name of the custom post type.
+ *
+ * @var string
+ */
+ public $post_type = 'showcase';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function rosetta_showcase_register() {
- $labels = array(
- 'name' => _x( 'Showcase', 'post type general name', 'rosetta' ),
- 'singular_name' => _x( 'Showcase Site', 'post type singular name', 'rosetta' ),
- 'add_new' => _x( 'Add New', 'showcase item', 'rosetta' ),
- 'add_new_item' => __( 'Add New Site', 'rosetta' ),
- 'edit_item' => __( 'Edit Site', 'rosetta' ),
- 'new_item' => __( 'New Site', 'rosetta' ),
- 'view_item' => __( 'View Site', 'rosetta' ),
- 'search_items' => __( 'Search Showcase', 'rosetta' ),
- 'not_found' => __( 'Nothing found', 'rosetta' ),
- 'not_found_in_trash' => __( 'Nothing found in Trash', 'rosetta' ),
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Constructor.
+ */
+ public function __construct() {
+ add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'show_ui' => true,
- 'rewrite' => false,
- 'has_archive' => true,
- 'capability_type' => 'post',
- 'map_meta_cap' => true,
- 'hierarchical' => false,
- 'supports' => array( 'title','excerpt' ),
- 'menu_icon' => 'dashicons-slides',
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Attaches hooks once plugins are loaded.
+ */
+ public function plugins_loaded() {
+ add_action( 'init', [ $this, 'register_post_type' ] );
+ add_filter( 'post_type_link', [ $this, 'filter_showcase_permalink' ], 10, 2 );
+ add_action( 'save_post', [ $this, 'save_showcase_url' ], 10, 2 );
+ add_action( 'manage_' . $this->post_type . '_posts_columns', [ $this, 'showcase_custom_columns' ] );
+ add_filter( 'manage_' . $this->post_type . '_posts_custom_column', [ $this, 'showcase_custom_column' ], 10, 2 );
+ add_filter( 'manage_edit-' . $this->post_type . '_sortable_columns', [ $this, 'showcase_sortable_columns' ], 10, 0 );
+ add_filter( 'sharing_meta_box_show', [ $this, 'disable_sharing_meta_box' ], 10, 2 );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_post_type( 'showcase', $args );
-}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Registers the custom post type used for the showcase.
+ */
+ public function register_post_type() {
+ $labels = array(
+ 'name' => _x( 'Showcase', 'post type general name', 'rosetta' ),
+ 'singular_name' => _x( 'Showcase Site', 'post type singular name', 'rosetta' ),
+ 'add_new' => _x( 'Add New', 'showcase item', 'rosetta' ),
+ 'add_new_item' => __( 'Add New Site', 'rosetta' ),
+ 'edit_item' => __( 'Edit Site', 'rosetta' ),
+ 'new_item' => __( 'New Site', 'rosetta' ),
+ 'view_item' => __( 'View Site', 'rosetta' ),
+ 'search_items' => __( 'Search Showcase', 'rosetta' ),
+ 'not_found' => __( 'Nothing found', 'rosetta' ),
+ 'not_found_in_trash' => __( 'Nothing found in Trash', 'rosetta' ),
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_filter( 'post_type_link', 'rosetta_filter_showcase_permalink', 10, 2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $args = array(
+ 'labels' => $labels,
+ 'public' => true,
+ 'show_ui' => true,
+ 'rewrite' => false,
+ 'has_archive' => false,
+ 'capability_type' => 'post',
+ 'map_meta_cap' => true,
+ 'hierarchical' => false,
+ 'show_in_nav_menus' => false,
+ 'can_export' => false,
+ 'exclude_from_search' => true,
+ 'supports' => array( 'title', 'excerpt' ),
+ 'menu_icon' => 'dashicons-slides',
+ 'register_meta_box_cb' => [ $this, 'register_showcase_meta_box' ],
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function rosetta_filter_showcase_permalink( $post_link, $post ) {
- if ( 'showcase' == $post->post_type ) {
- $url = get_post_meta( $post->ID, '_rosetta_showcase_url', true );
- if ( $url ) {
- return $url;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_post_type( $this->post_type, $args );
+ }
+
+ /**
+ * Replaces the default permalink with the URL to the website.
+ *
+ * @param string $post_link The post's permalink.
+ * @param WP_Post $post The post in question.
+ * @return string The filtered URL.
+ */
+ public function filter_showcase_permalink( $post_link, $post ) {
+ if ( $this->post_type === $post->post_type ) {
+ $url = get_post_meta( $post->ID, '_rosetta_showcase_url', true );
+ if ( $url ) {
+ return $url;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ return $post_link;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $post_link;
-}
</del><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_action( 'add_meta_boxes_showcase', 'rosetta_add_showcase_meta_box' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Replaces the default excerpt metabox with a custom one.
+ */
+ public function register_showcase_meta_box() {
+ remove_meta_box(
+ 'postexcerpt',
+ $this->post_type,
+ 'normal'
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function rosetta_add_showcase_meta_box() {
- remove_meta_box( 'postexcerpt', 'showcase', 'normal' );
- add_meta_box( 'rosetta_showcase_meta', __( 'Description and URL', 'rosetta' ), 'rosetta_showcase_meta_box', 'showcase', 'normal', 'default' );
-}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_meta_box(
+ 'rosetta_showcase_meta',
+ __( 'Description and URL', 'rosetta' ),
+ [ $this, 'showcase_meta_box' ],
+ $this->post_type,
+ 'normal',
+ 'default'
+ );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function rosetta_showcase_meta_box( $post ) {
- $url = get_post_meta( $post->ID, '_rosetta_showcase_url', true );
- ?>
- <p><label for="rosetta_showcase_url"><?php _e( 'URL' ) // core ?></label>
- <input style="margin-left: 0; width: 98%" name="rosetta_showcase_url" type="text" value="<?php echo esc_url( $url ); ?>" /></p>
- <label for="excerpt"><?php _e( 'Description' ) // core ?></label>
- <textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt"><?php echo $post->post_excerpt; // textarea_escaped ?></textarea>
- <?php
-}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Prints the metabox for the URL and description of a website.
+ *
+ * @param WP_Post $post Post object.
+ */
+ public function showcase_meta_box( $post ) {
+ $url = get_post_meta( $post->ID, '_rosetta_showcase_url', true );
+ ?>
+ <p><label for="rosetta_showcase_url"><?php _e( 'URL', 'rosetta' ); ?></label>
+ <input style="margin-left: 0; width: 98%" name="rosetta_showcase_url" type="text" value="<?php echo esc_url( $url ); ?>" /></p>
+ <label for="excerpt"><?php _e( 'Description', 'rosetta' ); ?></label>
+ <textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt"><?php echo $post->post_excerpt; // textarea_escaped ?></textarea>
+ <?php
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_action( 'save_post', 'save_showcase_url', 10, 2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Saves the URL of a website as a post meta.
+ *
+ * @param int $post_id Post ID.
+ * @param WP_Post $post Post object.
+ */
+ public function save_showcase_url( $post_id, $post ) {
+ if ( $this->post_type !== $post->post_type ) {
+ return;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function save_showcase_url( $post_id, $post ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! current_user_can( 'edit_post', $post_id ) ) {
+ return;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $post->post_type != 'showcase' ) {
- return;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( defined( 'DOING_AUTOSAVE' ) || defined( 'DOING_AJAX' ) ) {
+ return;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! current_user_can( 'edit_post', $post_id ) ) {
- return;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! isset( $_POST['rosetta_showcase_url'] ) ) {
+ return;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( defined( 'DOING_AUTOSAVE' ) || defined( 'DOING_AJAX' ) ) {
- return;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $url = esc_url_raw( $_POST['rosetta_showcase_url'] );
+
+ update_post_meta( $post_id, '_rosetta_showcase_url', $url );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! isset( $_POST['rosetta_showcase_url' ] ) ) {
- return;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Disables Jetpack's sharing meta box for a showcase item.
+ *
+ * @param $enable Whether the metabox is visible
+ * @param WP_Post $post Post object.
+ * @return bool True if metabox is visible, false if not.
+ */
+ public function disable_sharing_meta_box( $enable, $post ) {
+ if ( $this->post_type === $post->post_type ) {
+ return false;
+ }
+
+ return $enable;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $url = esc_url_raw( $_POST['rosetta_showcase_url'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Filters the columns displayed in the list table.
+ *
+ * @param array $columns An array of column names.
+ * @return array An array of column names.
+ */
+ public function showcase_custom_columns( $columns ) {
+ $columns = [
+ 'cb' => $columns['cb'],
+ 'shot' => __( 'Image', 'rosetta' ),
+ 'website' => __( 'Website', 'rosetta' ),
+ 'description' => __( 'Description', 'rosetta' ),
+ 'url' => __( 'URL', 'rosetta' ),
+ ];
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- update_post_meta( $post_id, '_rosetta_showcase_url', $url );
-}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $columns;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/* Show columns on the 'All Sites' page */
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Prints the content for each custom column in the list table.
+ *
+ * @param string $column The name of the column to display.
+ * @param int $post_id The current post ID.
+ */
+ public function showcase_custom_column( $column, $post_id ) {
+ switch ( $column ) {
+ case 'website' :
+ $title = _draft_or_post_title();
+ printf(
+ '<a class="row-title" href="%s" aria-label="%s">%s</a>',
+ get_edit_post_link( $post_id ),
+ /* translators: %s: post title */
+ esc_attr( sprintf( __( '“%s” (Edit)', 'rosetta' ), $title ) ),
+ $title
+ );
+ break;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_action( 'manage_showcase_posts_columns', 'rosetta_showcase_custom_columns' );
-add_filter( 'manage_showcase_posts_custom_column', 'rosetta_showcase_custom_column', 10, 2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'description' :
+ the_excerpt();
+ break;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function rosetta_showcase_custom_columns( $columns ) {
- $columns = array(
- 'cb' => $columns['cb'],
- 'shot' => __( 'Image' ), // core
- 'title' => __( 'Website' ), // core
- 'description' => __( 'Description' ), // core
- 'url' => __( 'URL' ), // core
- );
- return $columns;
-}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'url' :
+ $url = get_post_meta( $post_id, '_rosetta_showcase_url', true );
+ echo '<a href="' . esc_url( $url ) . '">' . esc_url_raw( $url ) . '</a>';
+ break;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function rosetta_showcase_custom_column( $column, $post_id ) {
- $post = get_post( $post_id );
-
- switch ( $column ) {
- case 'description' :
- the_excerpt();
- break;
- case 'url' :
- $url = get_post_meta( $post_id, '_rosetta_showcase_url', true );
- echo '<a href="' . esc_url( $url ) . '">' . esc_url_raw( $url ) . '</a>';
- break;
- case 'shot' :
- $url = esc_url( get_post_meta( $post_id, '_rosetta_showcase_url', true ) );
- if ( $url ) {
- echo '<a href="' . $url . '" target="_blank"><img width="100" src="https://wordpress.com/mshots/v1/' . urlencode( $url ) . '?w=100" /></a>';
- }
- break;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'shot' :
+ $url = esc_url( get_post_meta( $post_id, '_rosetta_showcase_url', true ) );
+ if ( $url ) {
+ echo '<a href="' . esc_url( $url ) . '" target="_blank"><img width="200" src="https://wordpress.com/mshots/v1/' . urlencode( $url ) . '?w=400" /></a>';
+ }
+ break;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-}
</del><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/* Add Showcase posts to the main loop and feed */
-//add_filter( 'pre_get_posts', 'rosetta_get_posts_with_showcase' );
-function rosetta_get_posts_with_showcase( $query ) {
- global $wp_the_query;
- if ( ( is_home() && $wp_the_query === $query ) || is_feed() ) {
- $query->set( 'post_type', array( 'post', 'showcase' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Filters the list table sortable columns.
+ *
+ * @return array An array of sortable columns.
+ */
+ public function showcase_sortable_columns() {
+ $columns = [
+ 'website' => 'title',
+ ];
+
+ return $columns;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $query;
-}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Retrieves four random showcase posts to be used on the front end.
+ *
+ * @return array List of showcase posts.
+ */
+ public function front() {
+ $posts = get_posts( [
+ 'post_type' => $this->post_type,
+ 'numberposts' => - 1,
+ ] );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-class Rosetta_Showcase {
- function front() {
- $posts = get_posts( array( 'post_type' => 'showcase', 'numberposts' => -1 ) );
</del><span class="cx" style="display: block; padding: 0 10px"> shuffle( $posts );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return array_slice( $posts, 0, 4 );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>