-
Notifications
You must be signed in to change notification settings - Fork 799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WP.com Posts: Show thumbnail on the posts list screen #19777
Changes from all commits
70d0c59
6e10b47
5ab2006
cb353b6
9814169
ed22007
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Files not needed to be distributed in the package. | ||
.gitattributes export-ignore | ||
.github/ export-ignore | ||
package.json export-ignore | ||
|
||
# Files to include in the mirror repo, but excluded via gitignore | ||
# /src/js/example.min.js production-include | ||
|
||
# Files to exclude from the mirror repo, but included in the monorepo. | ||
.gitignore production-exclude | ||
changelog/** production-exclude | ||
phpunit.xml.dist production-exclude | ||
tests/** production-exclude |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor/ | ||
node_modules/ | ||
wordpress/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# wpcom-posts | ||
|
||
Enhancements for the "Posts" screens on WordPress.com sites. | ||
|
||
## How to install wpcom-posts | ||
|
||
### Installation From Git Repo | ||
|
||
## Contribute | ||
|
||
## Get Help | ||
|
||
## Security | ||
|
||
Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic). | ||
|
||
## License | ||
|
||
wpcom-posts is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* Action Hooks for the WordPress.com's Posts enhancements. | ||
* | ||
* @package automattic/jetpack-wpcom-posts | ||
*/ | ||
|
||
namespace Automattic\Jetpack\WPcom\Posts; | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
return; | ||
} | ||
|
||
/** | ||
* Initializes the thumbnail enhancements. | ||
*/ | ||
function setup_thumbnail() { | ||
new Thumbnail(); | ||
} | ||
|
||
add_action( 'init', __NAMESPACE__ . '\setup_thumbnail' ); |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,54 @@ | ||||||||
{ | ||||||||
"name": "automattic/jetpack-wpcom-posts", | ||||||||
"description": "Enhancements for the \"Posts\" screens on WordPress.com sites.", | ||||||||
"type": "library", | ||||||||
"license": "GPL-2.0-or-later", | ||||||||
"require": {}, | ||||||||
"require-dev": { | ||||||||
"yoast/phpunit-polyfills": "0.2.0", | ||||||||
"automattic/jetpack-changelogger": "^1.1", | ||||||||
"automattic/wordbless": "dev-master" | ||||||||
}, | ||||||||
"autoload": { | ||||||||
"files": [ | ||||||||
"actions.php" | ||||||||
], | ||||||||
"classmap": [ | ||||||||
"src/" | ||||||||
] | ||||||||
}, | ||||||||
"scripts": { | ||||||||
"phpunit": [ | ||||||||
"@composer update", | ||||||||
"./vendor/phpunit/phpunit/phpunit --colors=always" | ||||||||
], | ||||||||
"test-coverage": [ | ||||||||
"@composer update", | ||||||||
"phpdbg -d memory_limit=2048M -d max_execution_time=900 -qrr ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\"" | ||||||||
], | ||||||||
"test-php": [ | ||||||||
"@composer phpunit" | ||||||||
], | ||||||||
"post-update-cmd": "php -r \"copy('vendor/automattic/wordbless/src/dbless-wpdb.php', 'wordpress/wp-content/db.php');\"" | ||||||||
}, | ||||||||
"repositories": [ | ||||||||
{ | ||||||||
"type": "path", | ||||||||
"url": "../*", | ||||||||
"options": { | ||||||||
"monorepo": true | ||||||||
} | ||||||||
} | ||||||||
], | ||||||||
"minimum-stability": "dev", | ||||||||
"prefer-stable": true, | ||||||||
"extra": { | ||||||||
"mirror-repo": "Automattic/jetpack-wpcom-posts", | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be okay to enable autotagger for this package.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't know about that, thanks! I guess we can maybe include an additional step in the Generate Wizard asking about this option, so it increases the visibility of this feature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sdixon194 Do you think we could add this to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing, we can do that! Opened an issue to track it here: #19816 |
||||||||
"changelogger": { | ||||||||
"link-template": "https://github.com/Automattic/jetpack-wpcom-posts/compare/v${old}...v${new}" | ||||||||
}, | ||||||||
"branch-alias": { | ||||||||
"dev-master": "0.1.x-dev" | ||||||||
} | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
This program is free software; you can redistribute it and/or | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We haven't typically added licenses to our packages until now, but you make a good point. I've asked in p2y3YZ-4v3-p2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, this was added by the Generate Wizard. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems @sdixon194 planned for it already 🥳 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"private": true, | ||
"description": "Enhancements for the \"Posts\" screens on WordPress.com sites.", | ||
"homepage": "https://jetpack.com", | ||
"bugs": { | ||
"url": "https://github.com/Automattic/jetpack/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Automattic/jetpack.git" | ||
}, | ||
"license": "GPL-2.0-or-later", | ||
"author": "Automattic", | ||
"scripts": { | ||
"build": "echo 'Not implemented.", | ||
"build-js": "echo 'Not implemented.", | ||
"build-production": "echo 'Not implemented.", | ||
"build-production-js": "echo 'Not implemented.", | ||
"clean": "true", | ||
"distclean": "rm -rf node_modules && yarn clean", | ||
"install-if-deps-outdated": "yarn install --check-files --production=false --frozen-lockfile", | ||
"validate-es5": "eslint --parser-options=ecmaVersion:5 --no-eslintrc --no-ignore" | ||
}, | ||
"devDependencies": {}, | ||
"engines": { | ||
"node": "^14.16.0", | ||
"yarn": "^1.3.2" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<phpunit bootstrap="tests/php/bootstrap.php" backupGlobals="false" colors="true"> | ||
<testsuites> | ||
<testsuite name="main"> | ||
<directory prefix="test" suffix=".php">tests/php</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">.</directory> | ||
<exclude> | ||
<directory suffix=".php">tests</directory> | ||
<directory suffix=".php">vendor</directory> | ||
<directory suffix=".php">wordpress</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* Thumbnail enhancements for the "Posts" screens on WordPress.com sites. | ||
* | ||
* @package automattic/jetpack-wpcom-posts | ||
*/ | ||
|
||
namespace Automattic\Jetpack\WPcom\Posts; | ||
|
||
/** | ||
* Class Thumbnail. | ||
*/ | ||
class Thumbnail { | ||
/** | ||
* Thumbnail constructor. | ||
*/ | ||
public function __construct() { | ||
add_filter( 'manage_posts_columns', array( $this, 'add_posts_column_header' ) ); | ||
add_filter( 'manage_pages_columns', array( $this, 'add_posts_column_header' ) ); | ||
add_action( 'manage_posts_custom_column', array( $this, 'display_posts_column_content' ), 10, 2 ); | ||
add_action( 'manage_pages_custom_column', array( $this, 'display_posts_column_content' ), 10, 2 ); | ||
add_action( 'admin_print_styles-edit.php', array( $this, 'load_columns_css' ) ); | ||
} | ||
|
||
/** | ||
* Adds a new column header for displaying the thumbnail of a post. | ||
* | ||
* @param array $columns An array of column names. | ||
* @return array An array of column names. | ||
*/ | ||
public function add_posts_column_header( $columns ) { | ||
// Place if before author. | ||
$pos = array_search( 'author', array_keys( $columns ), true ); | ||
if ( ! is_int( $pos ) ) { | ||
return $columns; | ||
} | ||
$chunks = array_chunk( $columns, $pos, true ); | ||
$chunks[0]['thumbnail'] = ''; // Deliberately empty. | ||
|
||
return call_user_func_array( 'array_merge', $chunks ); | ||
} | ||
|
||
/** | ||
* Displays the thumbnail content. | ||
* | ||
* @param string $column The name of the column to display. | ||
* @param int $post_id The current post ID. | ||
*/ | ||
public function display_posts_column_content( $column, $post_id ) { | ||
if ( 'thumbnail' !== $column ) { | ||
return; | ||
} | ||
|
||
echo get_the_post_thumbnail( $post_id, array( 50, 50 ), array( 'style' => 'height: auto;' ) ); | ||
} | ||
|
||
/** | ||
* Load CSS needed for the thumbnail column. | ||
*/ | ||
public function load_columns_css() { | ||
?> | ||
<style type="text/css"> | ||
.fixed .column-thumbnail { | ||
width: 5em; | ||
} | ||
</style> | ||
<?php | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* Bootstrap. | ||
* | ||
* @package automattic/ | ||
*/ | ||
|
||
/** | ||
* Include the composer autoloader. | ||
*/ | ||
require_once __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
/** | ||
* Load WorDBless | ||
*/ | ||
\WorDBless\Load::load(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName | ||
/** | ||
* Test methods from Automattic\Jetpack\WPcom\Posts\Thumbnail | ||
* | ||
* @package automattic/jetpack-wpcom-posts | ||
*/ | ||
|
||
namespace Automattic\Jetpack\WPcom\Posts; | ||
|
||
use WorDBless\BaseTestCase; | ||
|
||
/** | ||
* Class Test_Thumbnail | ||
*/ | ||
class Test_Thumbnail extends BaseTestCase { | ||
/** | ||
* Core class used to implement displaying posts in a list table. | ||
* | ||
* @var WP_Posts_List_Table | ||
*/ | ||
protected $table; | ||
|
||
/** | ||
* Test post. | ||
* | ||
* @var WP_Post | ||
*/ | ||
protected $post; | ||
|
||
/** | ||
* Setup runs before each test. | ||
* | ||
* @before | ||
*/ | ||
public function set_up() { | ||
new Thumbnail(); | ||
$this->table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => 'edit-page' ) ); | ||
|
||
$this->post = wp_insert_post( | ||
array( | ||
'post_status' => 'publish', | ||
'post_title' => 'Post title', | ||
'post_content' => 'Post content', | ||
'post_excerpt' => 'Post excerpt', | ||
'post_type' => 'post', | ||
) | ||
); | ||
|
||
add_filter( 'post_thumbnail_html', array( $this, 'mock_post_thumbnail_html' ), 10, 4 ); | ||
} | ||
|
||
public function tear_down() { | ||
remove_filter( 'post_thumbnail_html', array( $this, 'mock_post_thumbnail_html' ) ); | ||
} | ||
|
||
public function mock_post_thumbnail_html( $html, $post_id, $size, $attr ) { | ||
$width = $size[0]; | ||
$height = $size[1]; | ||
$style = $attr['style']; | ||
|
||
return "My thumbnail of $width x $height with a $style style"; | ||
} | ||
|
||
/** | ||
* Checks that a new column header for thumbnails is added to the posts list table. | ||
*/ | ||
public function test_thumbnail_column_header() { | ||
$columns = $this->table->get_columns(); | ||
$this->assertSame( '', $columns['thumbnail'] ); | ||
} | ||
|
||
/** | ||
* Checks that the post thumbnail is displayed in the new column cell new. | ||
*/ | ||
public function test_thumbnail_column_content() { | ||
$this->table->column_default( 'thumbnail' ); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is something that should be within the Jetpack plugin instead, or within wpcomsh, and then this package would only be the package itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or something that is used with the Config package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to leave this out of the Jetpack plugin for various reasons:
I do see value in setting up this via the Config package (which will be done on the WP.com sites), so I'll explore that approach.