diff --git a/projects/packages/classic-theme-helper/.phan/baseline.php b/projects/packages/classic-theme-helper/.phan/baseline.php index b031e9c7d6c1d..889311320576f 100644 --- a/projects/packages/classic-theme-helper/.phan/baseline.php +++ b/projects/packages/classic-theme-helper/.phan/baseline.php @@ -10,7 +10,7 @@ return [ // # Issue statistics: // PhanTypeMismatchArgumentInternal : 10+ occurrences - // PhanUndeclaredClassMethod : 6 occurrences + // PhanUndeclaredClassMethod : 5 occurrences // PhanTypeInvalidDimOffset : 2 occurrences // PhanTypeMismatchArgument : 2 occurrences // PhanNonClassMethodCall : 1 occurrence @@ -19,12 +19,10 @@ // PhanTypeMismatchProperty : 1 occurrence // PhanTypeMismatchPropertyProbablyReal : 1 occurrence // PhanTypePossiblyInvalidDimOffset : 1 occurrence - // PhanUndeclaredTypeReturnType : 1 occurrence // Currently, file_suppressions and directory_suppressions are the only supported suppressions 'file_suppressions' => [ '_inc/lib/tonesque.php' => ['PhanNonClassMethodCall', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchPropertyProbablyReal', 'PhanUndeclaredClassMethod'], - 'src/class-classic-theme-helper.php' => ['PhanUndeclaredClassMethod', 'PhanUndeclaredTypeReturnType'], 'src/class-featured-content.php' => ['PhanTypeComparisonToArray', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument', 'PhanTypeMismatchProperty', 'PhanTypePossiblyInvalidDimOffset'], ], // 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed. diff --git a/projects/packages/classic-theme-helper/changelog/update-move-featured-content-usage-from-module-to-package b/projects/packages/classic-theme-helper/changelog/update-move-featured-content-usage-from-module-to-package new file mode 100644 index 0000000000000..09f272197ec93 --- /dev/null +++ b/projects/packages/classic-theme-helper/changelog/update-move-featured-content-usage-from-module-to-package @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Classic Theme Helper: Move code from module to package diff --git a/projects/packages/classic-theme-helper/composer.json b/projects/packages/classic-theme-helper/composer.json index 9e50fb02c4f31..63193479be199 100644 --- a/projects/packages/classic-theme-helper/composer.json +++ b/projects/packages/classic-theme-helper/composer.json @@ -52,7 +52,7 @@ "extra": { "autotagger": true, "branch-alias": { - "dev-trunk": "0.2.x-dev" + "dev-trunk": "0.3.x-dev" }, "changelogger": { "link-template": "https://github.com/Automattic/jetpack-classic-theme-helper/compare/v${old}...v${new}" @@ -60,7 +60,7 @@ "mirror-repo": "Automattic/jetpack-classic-theme-helper", "textdomain": "jetpack-classic-theme-helper", "version-constants": { - "::PACKAGE_VERSION": "src/class-classic-theme-helper.php" + "::PACKAGE_VERSION": "src/class-main.php" } }, "suggest": { diff --git a/projects/packages/classic-theme-helper/package.json b/projects/packages/classic-theme-helper/package.json index d713079212caa..72a8aabe0f261 100644 --- a/projects/packages/classic-theme-helper/package.json +++ b/projects/packages/classic-theme-helper/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@automattic/jetpack-classic-theme-helper", - "version": "0.2.1", + "version": "0.3.0-alpha", "description": "Features used with classic themes", "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/classic-theme-helper/#readme", "bugs": { diff --git a/projects/packages/classic-theme-helper/src/class-featured-content.php b/projects/packages/classic-theme-helper/src/class-featured-content.php index 08cf2b96c5588..da6ce8b0265bb 100644 --- a/projects/packages/classic-theme-helper/src/class-featured-content.php +++ b/projects/packages/classic-theme-helper/src/class-featured-content.php @@ -2,12 +2,15 @@ /** * Theme Tools: functions for Featured Content enhancements. * - * @package automattic/jetpack + * @package automattic/jetpack-classic-theme-helper */ -use Automattic\Jetpack\Assets; +namespace Automattic\Jetpack\Classic_Theme_Helper; -if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'plugins.php' !== $GLOBALS['pagenow'] ) { +use Automattic\Jetpack\Assets; +use WP_Customize_Manager; +use WP_Query; +if ( ! class_exists( __NAMESPACE__ . '\Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'plugins.php' !== $GLOBALS['pagenow'] ) { /** * Featured Content. @@ -767,7 +770,7 @@ function wpcom_rest_api_featured_content_copy_plugin_actions( $copy_dirs ) { $copy_dirs[] = __FILE__; return $copy_dirs; } - add_action( 'restapi_theme_action_copy_dirs', 'wpcom_rest_api_featured_content_copy_plugin_actions' ); + add_action( 'restapi_theme_action_copy_dirs', __NAMESPACE__ . '\wpcom_rest_api_featured_content_copy_plugin_actions' ); /** * Delayed initialization for API Requests. @@ -780,7 +783,7 @@ function wpcom_rest_request_before_callbacks( $request ) { } if ( defined( 'IS_WPCOM' ) && IS_WPCOM && defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) { - add_filter( 'rest_request_before_callbacks', 'wpcom_rest_request_before_callbacks' ); + add_filter( 'rest_request_before_callbacks', __NAMESPACE__ . '\wpcom_rest_request_before_callbacks' ); } Featured_Content::setup(); diff --git a/projects/packages/classic-theme-helper/src/class-classic-theme-helper.php b/projects/packages/classic-theme-helper/src/class-main.php similarity index 74% rename from projects/packages/classic-theme-helper/src/class-classic-theme-helper.php rename to projects/packages/classic-theme-helper/src/class-main.php index c8e0581aea31f..b7690e8ae9487 100644 --- a/projects/packages/classic-theme-helper/src/class-classic-theme-helper.php +++ b/projects/packages/classic-theme-helper/src/class-main.php @@ -5,14 +5,16 @@ * @package automattic/jetpack-classic-theme-helper */ -namespace Automattic\Jetpack; +namespace Automattic\Jetpack\Classic_Theme_Helper; + +use WP_Error; /** - * Classic Theme Helper. + * Classic Theme Helper Loader. */ -class Classic_Theme_Helper { +class Main { - const PACKAGE_VERSION = '0.2.1'; + const PACKAGE_VERSION = '0.3.0-alpha'; /** * Modules to include. @@ -21,16 +23,28 @@ class Classic_Theme_Helper { */ public $modules = array( 'class-featured-content.php', - 'responsive-videos.php', + // 'responsive-videos.php', ); + /** Holds the singleton instance of the Loader + * + * @var Main + */ + public static $instance = null; + /** - * Initialize Classic Theme Helper. + * Initialize the Loader. */ - public function init() { - add_action( 'plugins_loaded', array( $this, 'load_modules' ) ); - add_action( 'init', array( __CLASS__, 'jetpack_load_theme_tools' ), 30 ); - add_action( 'after_setup_theme', array( __CLASS__, 'jetpack_load_theme_compat' ), -1 ); + public static function init() { + if ( ! self::$instance ) { + self::$instance = new Main(); + add_action( 'plugins_loaded', array( self::$instance, 'load_modules' ) ); + // TODO Commenting below since we still load them from theme-tools module + // add_action( 'init', array( __CLASS__, 'jetpack_load_theme_tools' ), 30 ); + // add_action( 'after_setup_theme', array( __CLASS__, 'jetpack_load_theme_compat' ), -1 ); + } + + return self::$instance; } /** @@ -43,7 +57,7 @@ public function load_modules() { // @param array $modules Array of modules to include. $modules = apply_filters( 'jetpack_classic_theme_helper_modules', $this->modules ); foreach ( $modules as $module ) { - require_once __DIR__ . $module; + require_once __DIR__ . '/' . $module; } } @@ -110,3 +124,4 @@ private static function jetpack_require_compat_file( $key, $files ) { } } } +Main::init(); diff --git a/projects/plugins/classic-theme-helper-plugin/changelog/update-move-featured-content-usage-from-module-to-package b/projects/plugins/classic-theme-helper-plugin/changelog/update-move-featured-content-usage-from-module-to-package new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/classic-theme-helper-plugin/changelog/update-move-featured-content-usage-from-module-to-package @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/classic-theme-helper-plugin/changelog/update-move-featured-content-usage-from-module-to-package#2 b/projects/plugins/classic-theme-helper-plugin/changelog/update-move-featured-content-usage-from-module-to-package#2 new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/classic-theme-helper-plugin/changelog/update-move-featured-content-usage-from-module-to-package#2 @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/classic-theme-helper-plugin/changelog/update-move-featured-content-usage-from-module-to-package#3 b/projects/plugins/classic-theme-helper-plugin/changelog/update-move-featured-content-usage-from-module-to-package#3 new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/classic-theme-helper-plugin/changelog/update-move-featured-content-usage-from-module-to-package#3 @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/classic-theme-helper-plugin/changelog/update-move-featured-content-usage-from-module-to-package#4 b/projects/plugins/classic-theme-helper-plugin/changelog/update-move-featured-content-usage-from-module-to-package#4 new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/classic-theme-helper-plugin/changelog/update-move-featured-content-usage-from-module-to-package#4 @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/classic-theme-helper-plugin/composer.lock b/projects/plugins/classic-theme-helper-plugin/composer.lock index b2e265afece3d..49c773a9e8efc 100644 --- a/projects/plugins/classic-theme-helper-plugin/composer.lock +++ b/projects/plugins/classic-theme-helper-plugin/composer.lock @@ -192,7 +192,7 @@ "dist": { "type": "path", "url": "../../packages/classic-theme-helper", - "reference": "4851293db36b3c568391618cd733ab7618c95ae6" + "reference": "0a0b72c656b3949e67db20779c1f8bab8d8426fb" }, "require": { "automattic/jetpack-assets": "@dev", @@ -210,7 +210,7 @@ "extra": { "autotagger": true, "branch-alias": { - "dev-trunk": "0.2.x-dev" + "dev-trunk": "0.3.x-dev" }, "changelogger": { "link-template": "https://github.com/Automattic/jetpack-classic-theme-helper/compare/v${old}...v${new}" @@ -218,7 +218,7 @@ "mirror-repo": "Automattic/jetpack-classic-theme-helper", "textdomain": "jetpack-classic-theme-helper", "version-constants": { - "::PACKAGE_VERSION": "src/class-classic-theme-helper.php" + "::PACKAGE_VERSION": "src/class-main.php" } }, "autoload": { diff --git a/projects/plugins/jetpack/.phan/baseline.php b/projects/plugins/jetpack/.phan/baseline.php index 9ee3f4ee498b7..6a8552dfaa4e4 100644 --- a/projects/plugins/jetpack/.phan/baseline.php +++ b/projects/plugins/jetpack/.phan/baseline.php @@ -14,7 +14,7 @@ // PhanPluginDuplicateConditionalNullCoalescing : 280+ occurrences // PhanNoopNew : 200+ occurrences // PhanTypeMismatchReturn : 150+ occurrences - // PhanTypeMismatchReturnProbablyReal : 150+ occurrences + // PhanTypeMismatchReturnProbablyReal : 140+ occurrences // PhanDeprecatedFunction : 120+ occurrences // PhanTypePossiblyInvalidDimOffset : 95+ occurrences // PhanRedundantCondition : 70+ occurrences @@ -39,6 +39,7 @@ // PhanUndeclaredFunction : 20+ occurrences // PhanPluginDuplicateExpressionAssignmentOperation : 15+ occurrences // PhanPluginMixedKeyNoKey : 15+ occurrences + // PhanRedefineFunction : 15+ occurrences // PhanSuspiciousMagicConstant : 15+ occurrences // PhanTypeExpectedObjectPropAccessButGotNull : 15+ occurrences // PhanTypeMismatchArgumentNullableInternal : 15+ occurrences @@ -46,17 +47,17 @@ // PhanUndeclaredMethod : 15+ occurrences // PhanRedefineClass : 10+ occurrences // PhanRedundantConditionInLoop : 10+ occurrences - // PhanTypeComparisonToArray : 10+ occurrences // PhanTypeInvalidLeftOperandOfNumericOp : 10+ occurrences // PhanTypeMismatchProperty : 10+ occurrences // PhanTypeMismatchReturnNullable : 10+ occurrences + // PhanTypeComparisonToArray : 9 occurrences // PhanPluginRedundantAssignment : 8 occurrences // PhanDeprecatedClass : 7 occurrences // PhanTypeMismatchArgumentInternalReal : 7 occurrences // PhanCommentAbstractOnInheritedMethod : 6 occurrences - // PhanRedefineFunction : 6 occurrences // PhanImpossibleCondition : 5 occurrences // PhanNonClassMethodCall : 5 occurrences + // PhanRedefinedClassReference : 5 occurrences // PhanTypeArraySuspiciousNull : 5 occurrences // PhanTypeMismatchDimAssignment : 5 occurrences // PhanTypeSuspiciousStringExpression : 5 occurrences @@ -95,7 +96,6 @@ // PhanPluginRedundantAssignmentInLoop : 1 occurrence // PhanTypeComparisonFromArray : 1 occurrence // PhanTypeInstantiateAbstract : 1 occurrence - // PhanTypeInvalidCallableArraySize : 1 occurrence // PhanTypeSuspiciousEcho : 1 occurrence // PhanTypeVoidArgument : 1 occurrence // PhanUndeclaredExtendedClass : 1 occurrence @@ -165,7 +165,7 @@ '_inc/lib/icalendar-reader.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginDuplicateExpressionAssignmentOperation', 'PhanPossiblyUndeclaredVariable', 'PhanRedundantCondition', 'PhanTypeInvalidLeftOperandOfNumericOp', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypePossiblyInvalidDimOffset', 'PhanUndeclaredProperty'], '_inc/lib/markdown/extra.php' => ['PhanImpossibleConditionInLoop', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchReturn', 'PhanUndeclaredProperty'], '_inc/lib/plans.php' => ['PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'], - '_inc/lib/tonesque.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal'], + '_inc/lib/tonesque.php' => ['PhanRedefineClass', 'PhanRedefinedClassReference', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal'], '_inc/lib/widgets.php' => ['PhanRedundantConditionInLoop', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchReturn'], '_inc/social-logos.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'class-jetpack-gallery-settings.php' => ['PhanNoopNew'], @@ -441,7 +441,10 @@ 'modules/subscriptions.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypeSuspiciousNonTraversableForeach'], 'modules/subscriptions/subscribe-modal/class-jetpack-subscribe-modal.php' => ['PhanTypeMismatchReturnNullable'], 'modules/subscriptions/views.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMissingReturn', 'PhanTypePossiblyInvalidDimOffset'], - 'modules/theme-tools/compat/twentysixteen.php' => ['PhanParamTooMany'], + 'modules/theme-tools/compat/twentyfifteen.php' => ['PhanRedefineFunction'], + 'modules/theme-tools/compat/twentyfourteen.php' => ['PhanRedefineFunction'], + 'modules/theme-tools/compat/twentynineteen.php' => ['PhanRedefineFunction'], + 'modules/theme-tools/compat/twentysixteen.php' => ['PhanParamTooMany', 'PhanRedefineFunction'], 'modules/theme-tools/compat/twentytwenty.php' => ['PhanParamTooMany'], 'modules/theme-tools/content-options/author-bio.php' => ['PhanTypeMismatchArgument'], 'modules/theme-tools/content-options/blog-display.php' => ['PhanPluginDuplicateExpressionAssignmentOperation'], @@ -449,8 +452,8 @@ 'modules/theme-tools/content-options/featured-images-fallback.php' => ['PhanTypeMismatchArgument', 'PhanTypePossiblyInvalidDimOffset'], 'modules/theme-tools/content-options/featured-images.php' => ['PhanPluginSimplifyExpressionBool', 'PhanTypeMismatchArgument'], 'modules/theme-tools/content-options/post-details.php' => ['PhanTypeArraySuspiciousNullable'], - 'modules/theme-tools/featured-content.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeComparisonToArray', 'PhanTypeInvalidCallableArraySize', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchProperty', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypeMissingReturn', 'PhanTypePossiblyInvalidDimOffset'], 'modules/theme-tools/random-redirect.php' => ['PhanTypeMismatchArgument'], + 'modules/theme-tools/responsive-videos.php' => ['PhanRedefineFunction'], 'modules/theme-tools/site-breadcrumbs.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchReturn'], 'modules/theme-tools/site-logo/inc/class-site-logo.php' => ['PhanRedundantCondition', 'PhanTypeComparisonToArray', 'PhanTypeMismatchReturn'], 'modules/theme-tools/site-logo/inc/functions.php' => ['PhanTypeMismatchReturnProbablyReal'], diff --git a/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package b/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package new file mode 100644 index 0000000000000..72a1bb66d6ae5 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package @@ -0,0 +1,4 @@ +Significance: minor +Type: other + +Classic Theme Helper: Move code from module to package diff --git a/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#2 b/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#2 new file mode 100644 index 0000000000000..a1c1831fa1ef7 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#2 @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Updated composer.lock. + + diff --git a/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#3 b/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#3 new file mode 100644 index 0000000000000..a1c1831fa1ef7 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#3 @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Updated composer.lock. + + diff --git a/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#4 b/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#4 new file mode 100644 index 0000000000000..a1c1831fa1ef7 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#4 @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Updated composer.lock. + + diff --git a/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#5 b/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#5 new file mode 100644 index 0000000000000..a1c1831fa1ef7 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#5 @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Updated composer.lock. + + diff --git a/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#6 b/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#6 new file mode 100644 index 0000000000000..a1c1831fa1ef7 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-move-featured-content-usage-from-module-to-package#6 @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Updated composer.lock. + + diff --git a/projects/plugins/jetpack/composer.json b/projects/plugins/jetpack/composer.json index 3c03ebc9af638..973d7eedab19a 100644 --- a/projects/plugins/jetpack/composer.json +++ b/projects/plugins/jetpack/composer.json @@ -21,6 +21,7 @@ "automattic/jetpack-blocks": "@dev", "automattic/jetpack-boost-speed-score": "@dev", "automattic/jetpack-calypsoify": "@dev", + "automattic/jetpack-classic-theme-helper": "@dev", "automattic/jetpack-compat": "@dev", "automattic/jetpack-composer-plugin": "@dev", "automattic/jetpack-config": "@dev", diff --git a/projects/plugins/jetpack/composer.lock b/projects/plugins/jetpack/composer.lock index 80ca724eb5d39..833530952f711 100644 --- a/projects/plugins/jetpack/composer.lock +++ b/projects/plugins/jetpack/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cd7756a6d6bc9f913706f8ef6ffb40a1", + "content-hash": "62403191018bfe60b0272ef03acb944e", "packages": [ { "name": "automattic/jetpack-a8c-mc-stats", @@ -788,6 +788,74 @@ "relative": true } }, + { + "name": "automattic/jetpack-classic-theme-helper", + "version": "dev-trunk", + "dist": { + "type": "path", + "url": "../../packages/classic-theme-helper", + "reference": "0a0b72c656b3949e67db20779c1f8bab8d8426fb" + }, + "require": { + "automattic/jetpack-assets": "@dev", + "php": ">=7.0" + }, + "require-dev": { + "automattic/jetpack-changelogger": "@dev", + "automattic/wordbless": "dev-master", + "yoast/phpunit-polyfills": "1.1.0" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "type": "jetpack-library", + "extra": { + "autotagger": true, + "branch-alias": { + "dev-trunk": "0.3.x-dev" + }, + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-classic-theme-helper/compare/v${old}...v${new}" + }, + "mirror-repo": "Automattic/jetpack-classic-theme-helper", + "textdomain": "jetpack-classic-theme-helper", + "version-constants": { + "::PACKAGE_VERSION": "src/class-main.php" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "scripts": { + "build-production": [ + "pnpm run build-production" + ], + "build-development": [ + "pnpm run build" + ], + "phpunit": [ + "./vendor/phpunit/phpunit/phpunit --colors=always" + ], + "post-install-cmd": [ + "WorDBless\\Composer\\InstallDropin::copy" + ], + "post-update-cmd": [ + "WorDBless\\Composer\\InstallDropin::copy" + ], + "test-php": [ + "@composer phpunit" + ] + }, + "license": [ + "GPL-2.0-or-later" + ], + "description": "Features used with classic themes", + "transport-options": { + "relative": true + } + }, { "name": "automattic/jetpack-compat", "version": "dev-trunk", @@ -5938,6 +6006,7 @@ "automattic/jetpack-blocks": 20, "automattic/jetpack-boost-speed-score": 20, "automattic/jetpack-calypsoify": 20, + "automattic/jetpack-classic-theme-helper": 20, "automattic/jetpack-compat": 20, "automattic/jetpack-composer-plugin": 20, "automattic/jetpack-config": 20, diff --git a/projects/plugins/jetpack/modules/theme-tools/featured-content.php b/projects/plugins/jetpack/modules/theme-tools/featured-content.php index 3270f6fb70025..c49d9f0e8e9c3 100644 --- a/projects/plugins/jetpack/modules/theme-tools/featured-content.php +++ b/projects/plugins/jetpack/modules/theme-tools/featured-content.php @@ -5,10 +5,6 @@ * @package automattic/jetpack */ -use Automattic\Jetpack\Constants; - -// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. - if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'plugins.php' !== $GLOBALS['pagenow'] ) { /** @@ -31,15 +27,17 @@ * designate a featured post tag to associate posts with. Since this tag now has * special meaning beyond that of a normal tags, users will have the ability to * hide it from the front-end of their site. + * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. */ class Featured_Content { - /** * The maximum number of posts that a Featured Content area can contain. We * define a default value here but themes can override this by defining a * "max_posts" entry in the second parameter passed in the call to * add_theme_support( 'featured-content' ). * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @see Featured_Content::init() * @var int */ @@ -51,6 +49,7 @@ class Featured_Content { * 'post_types' argument (string|array) in the call to * add_theme_support( 'featured-content' ). * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @see Featured_Content::init() * @var array */ @@ -60,6 +59,7 @@ class Featured_Content { * The tag that is used to mark featured content. Users can define * a custom tag name that will be stored in this variable. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @see Featured_Content::hide_featured_term * @var string */ @@ -69,9 +69,12 @@ class Featured_Content { * Instantiate. * * All custom functionality will be hooked into the "init" action. + * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. */ public static function setup() { - add_action( 'init', array( __CLASS__, 'init' ), 30 ); + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content::setup' ); + Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::setup(); } /** @@ -83,70 +86,13 @@ public static function setup() { * If no theme support is found there is no need to hook into WordPress. We'll * just return early instead. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. + * * @uses Featured_Content::$max_posts */ public static function init() { - $theme_support = get_theme_support( 'featured-content' ); - - // Return early if theme does not support featured content. - if ( ! $theme_support ) { - return; - } - - /* - * An array of named arguments must be passed as the second parameter - * of add_theme_support(). - */ - if ( ! isset( $theme_support[0] ) ) { - return; - } - - if ( isset( $theme_support[0]['featured_content_filter'] ) ) { - $theme_support[0]['filter'] = $theme_support[0]['featured_content_filter']; - unset( $theme_support[0]['featured_content_filter'] ); - } - - // Return early if "filter" has not been defined. - if ( ! isset( $theme_support[0]['filter'] ) ) { - return; - } - - // Theme can override the number of max posts. - if ( isset( $theme_support[0]['max_posts'] ) ) { - self::$max_posts = absint( $theme_support[0]['max_posts'] ); - } - - add_filter( $theme_support[0]['filter'], array( __CLASS__, 'get_featured_posts' ) ); - if ( ! wp_is_block_theme() ) { - add_action( 'customize_register', array( __CLASS__, 'customize_register' ), 9 ); - } - add_action( 'admin_init', array( __CLASS__, 'register_setting' ) ); - add_action( 'save_post', array( __CLASS__, 'delete_transient' ) ); - add_action( 'delete_post_tag', array( __CLASS__, 'delete_post_tag' ) ); - add_action( 'customize_controls_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); - add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) ); - add_action( 'switch_theme', array( __CLASS__, 'switch_theme' ) ); - add_action( 'switch_theme', array( __CLASS__, 'delete_transient' ) ); - add_action( 'wp_loaded', array( __CLASS__, 'wp_loaded' ) ); - add_action( 'update_option_featured-content', array( __CLASS__, 'flush_post_tag_cache' ), 10, 2 ); - add_action( 'delete_option_featured-content', array( __CLASS__, 'flush_post_tag_cache' ), 10, 2 ); - add_action( 'split_shared_term', array( __CLASS__, 'jetpack_update_featured_content_for_split_terms', 10, 4 ) ); - - if ( isset( $theme_support[0]['additional_post_types'] ) ) { - $theme_support[0]['post_types'] = array_merge( array( 'post' ), (array) $theme_support[0]['additional_post_types'] ); - unset( $theme_support[0]['additional_post_types'] ); - } - - // Themes can allow Featured Content pages. - if ( isset( $theme_support[0]['post_types'] ) ) { - self::$post_types = array_merge( self::$post_types, (array) $theme_support[0]['post_types'] ); - self::$post_types = array_unique( self::$post_types ); - - // register post_tag support for each post type. - foreach ( self::$post_types as $post_type ) { - register_taxonomy_for_object_type( 'post_tag', $post_type ); - } - } + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\init' ); + return Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::init(); } /** @@ -154,17 +100,12 @@ public static function init() { * * Has to run on wp_loaded so that the preview filters of the customizer * have a chance to alter the value. + * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. */ public static function wp_loaded() { - if ( self::get_setting( 'hide-tag' ) ) { - $settings = self::get_setting(); - - // This is done before setting filters for get_terms in order to avoid an infinite filter loop. - self::$tag = get_term_by( 'name', $settings['tag-name'], 'post_tag' ); - - add_filter( 'get_terms', array( __CLASS__, 'hide_featured_term' ), 10, 3 ); - add_filter( 'get_the_terms', array( __CLASS__, 'hide_the_featured_term' ), 10, 3 ); - } + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\wp_loaded' ); + return Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::wp_loaded(); } /** @@ -175,28 +116,14 @@ public static function wp_loaded() { * the "filter" key in the array passed as the $args parameter during the call * to: add_theme_support( 'featured-content', $args ). * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @uses Featured_Content::get_featured_post_ids() * * @return array */ public static function get_featured_posts() { - $post_ids = self::get_featured_post_ids(); - - // No need to query if there is are no featured posts. - if ( empty( $post_ids ) ) { - return array(); - } - - $featured_posts = get_posts( - array( - 'include' => $post_ids, - 'posts_per_page' => count( $post_ids ), // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page - 'post_type' => self::$post_types, - 'suppress_filters' => false, - ) - ); - - return $featured_posts; + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\get_featured_posts' ); + return Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::get_featured_posts(); } /** @@ -207,74 +134,12 @@ public static function get_featured_posts() { * * Sets the "featured_content_ids" transient. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @return array Array of post IDs. */ public static function get_featured_post_ids() { - // Return array of cached results if they exist. - $featured_ids = get_transient( 'featured_content_ids' ); - if ( ! empty( $featured_ids ) ) { - return array_map( - 'absint', - /** - * Filter the list of Featured Posts IDs. - * - * @module theme-tools - * - * @since 2.7.0 - * - * @param array $featured_ids Array of post IDs. - */ - apply_filters( 'featured_content_post_ids', (array) $featured_ids ) - ); - } - - $settings = self::get_setting(); - - // Return empty array if no tag name is set. - $term = get_term_by( 'name', $settings['tag-name'], 'post_tag' ); - if ( ! $term ) { - $term = get_term_by( 'id', $settings['tag-id'], 'post_tag' ); - } - if ( $term ) { - $tag = $term->term_id; - } else { - /** This action is documented in modules/theme-tools/featured-content.php */ - return apply_filters( 'featured_content_post_ids', array() ); - } - - // Back compat for installs that have the quantity option still set. - $quantity = isset( $settings['quantity'] ) ? $settings['quantity'] : self::$max_posts; - - // Query for featured posts. - $featured = get_posts( - array( - 'numberposts' => $quantity, - 'post_type' => self::$post_types, - 'suppress_filters' => false, - 'tax_query' => array( - array( - 'field' => 'term_id', - 'taxonomy' => 'post_tag', - 'terms' => $tag, - ), - ), - ) - ); - - // Return empty array if no featured content exists. - if ( ! $featured ) { - /** This action is documented in modules/theme-tools/featured-content.php */ - return apply_filters( 'featured_content_post_ids', array() ); - } - - // Ensure correct format before save/return. - $featured_ids = wp_list_pluck( (array) $featured, 'ID' ); - $featured_ids = array_map( 'absint', $featured_ids ); - - set_transient( 'featured_content_ids', $featured_ids ); - - /** This action is documented in modules/theme-tools/featured-content.php */ - return apply_filters( 'featured_content_post_ids', $featured_ids ); + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\get_featured_post_ids' ); + return Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::get_featured_post_ids(); } /** @@ -282,10 +147,12 @@ public static function get_featured_post_ids() { * * Hooks in the "save_post" action. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @see Featured_Content::validate_settings(). */ public static function delete_transient() { - delete_transient( 'featured_content_ids' ); + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\delete_transient' ); + Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::delete_transient(); } /** @@ -293,21 +160,13 @@ public static function delete_transient() { * * Hooks in the "update_option_featured-content" action. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @param array $prev Previous option data. * @param array $opts New option data. */ public static function flush_post_tag_cache( $prev, $opts ) { - if ( ! empty( $opts ) && ! empty( $opts['tag-id'] ) ) { - $query = new WP_Query( - array( - 'tag_id' => (int) $opts['tag-id'], - 'posts_per_page' => -1, - ) - ); - foreach ( $query->posts as $post ) { - wp_cache_delete( $post->ID, 'post_tag_relationships' ); - } - } + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\flush_post_tag_cache' ); + Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::flush_post_tag_cache( $prev, $opts ); } /** @@ -318,46 +177,16 @@ public static function flush_post_tag_cache( $prev, $opts ) { * Hooked onto the 'pre_get_posts' action, this changes the parameters of the * query before it gets any posts. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @uses Featured_Content::get_featured_post_ids(); * @uses Featured_Content::get_setting(); * @param WP_Query $query WP_Query object. * @return WP_Query Possibly modified WP_Query */ public static function pre_get_posts( $query ) { + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\pre_get_posts' ); - // Bail if not home or not main query. - if ( ! $query->is_home() || ! $query->is_main_query() ) { - return; - } - - // Bail if the blog page is not the front page. - if ( 'posts' !== get_option( 'show_on_front' ) ) { - return; - } - - $featured = self::get_featured_post_ids(); - - // Bail if no featured posts. - if ( ! $featured ) { - return; - } - - $settings = self::get_setting(); - - // Bail if the user wants featured posts always displayed. - if ( $settings['show-all'] ) { - return; - } - - // We need to respect post ids already in the blocklist. - $post__not_in = $query->get( 'post__not_in' ); - - if ( ! empty( $post__not_in ) ) { - $featured = array_merge( (array) $post__not_in, $featured ); - $featured = array_unique( $featured ); - } - - $query->set( 'post__not_in', $featured ); + return Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::pre_get_posts( $query ); } /** @@ -369,21 +198,15 @@ public static function pre_get_posts( $query ) { * * Hooks in the "delete_post_tag" action. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @see Featured_Content::validate_settings(). * * @param int $tag_id The term_id of the tag that has been deleted. * @return void */ public static function delete_post_tag( $tag_id ) { - $settings = self::get_setting(); - - if ( empty( $settings['tag-id'] ) || $tag_id != $settings['tag-id'] ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual - return; - } - - $settings['tag-id'] = 0; - $settings = self::validate_settings( $settings ); - update_option( 'featured-content', $settings ); + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\delete_post_tag' ); + Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::delete_post_tag( $tag_id ); } /** @@ -392,6 +215,7 @@ public static function delete_post_tag( $tag_id ) { * * Hooks into the "get_terms" filter. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @uses Featured_Content::get_setting() * * @param array $terms A list of term objects. This is the return value of get_terms(). @@ -400,50 +224,9 @@ public static function delete_post_tag( $tag_id ) { * @return array $terms */ public static function hide_featured_term( $terms, $taxonomies, $args ) { + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\hide_featured_term' ); - // This filter is only appropriate on the front-end. - if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ) { - return $terms; - } - - // WordPress defines the parameter as `array`, but it passes null if `get_terms( $args )` was called - // without a 'taxonomy' in $args. - if ( ! is_array( $taxonomies ) ) { - return $terms; - } - - // We only want to hide the featured tag. - if ( ! in_array( 'post_tag', $taxonomies, true ) ) { - return $terms; - } - - // Bail if no terms were returned. - if ( empty( $terms ) ) { - return $terms; - } - - // Bail if term objects are unavailable. - if ( 'all' !== $args['fields'] ) { - return $terms; - } - - $settings = self::get_setting(); - - if ( false !== self::$tag ) { - foreach ( $terms as $order => $term ) { - if ( - is_object( $term ) - && ( - $settings['tag-id'] === $term->term_id - || $settings['tag-name'] === $term->name - ) - ) { - unset( $terms[ $order ] ); - } - } - } - - return $terms; + return Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::hide_featured_term( $terms, $taxonomies, $args ); } /** @@ -452,6 +235,7 @@ public static function hide_featured_term( $terms, $taxonomies, $args ) { * * Hooks into the "get_the_terms" filter. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @uses Featured_Content::get_setting() * * @param array $terms A list of term objects. This is the return value of get_the_terms(). @@ -460,155 +244,54 @@ public static function hide_featured_term( $terms, $taxonomies, $args ) { * @return array $terms */ public static function hide_the_featured_term( $terms, $id, $taxonomy ) { + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\hide_the_featured_term' ); - // This filter is only appropriate on the front-end. - if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ) { - return $terms; - } - - // Make sure we are in the correct taxonomy. - if ( 'post_tag' !== $taxonomy ) { - return $terms; - } - - // No terms? Return early! - if ( empty( $terms ) ) { - return $terms; - } - - $settings = self::get_setting(); - $tag = get_term_by( 'name', $settings['tag-name'], 'post_tag' ); - - if ( false !== $tag ) { - foreach ( $terms as $order => $term ) { - if ( $settings['tag-id'] === $term->term_id || $settings['tag-name'] === $term->name ) { - unset( $terms[ $order ] ); - } - } - } - - return $terms; + return Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::hide_the_featured_term( $terms, $id, $taxonomy ); } /** * Register custom setting on the Settings -> Reading screen. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @uses Featured_Content::render_form() * @uses Featured_Content::validate_settings() * * @return void */ public static function register_setting() { - add_settings_field( 'featured-content', __( 'Featured Content', 'jetpack' ), array( __CLASS__, 'render_form' ), 'reading' ); - - // Register sanitization callback for the Customizer. - register_setting( 'featured-content', 'featured-content', array( __CLASS__, 'validate_settings' ) ); + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\register_setting' ); + Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::register_setting(); } /** * Add settings to the Customizer. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ public static function customize_register( $wp_customize ) { - $wp_customize->add_section( - 'featured_content', - array( - 'title' => esc_html__( 'Featured Content', 'jetpack' ), - 'description' => sprintf( - /* translators: %1$s: Link to 'featured' admin tag view. %2$s: Max number of posts shown by theme in featured content area. */ - __( 'Easily feature all posts with the "featured" tag or a tag of your choice. Your theme supports up to %2$s posts in its featured content area.', 'jetpack' ), - admin_url( '/edit.php?tag=featured' ), - absint( self::$max_posts ) - ), - 'priority' => 130, - 'theme_supports' => 'featured-content', - ) - ); - - /* - Add Featured Content settings. - * - * Sanitization callback registered in Featured_Content::validate_settings(). - * See https://themeshaper.com/2013/04/29/validation-sanitization-in-customizer/comment-page-1/#comment-12374 - */ - $wp_customize->add_setting( - 'featured-content[tag-name]', - array( - 'type' => 'option', - 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), - ) - ); - $wp_customize->add_setting( - 'featured-content[hide-tag]', - array( - 'default' => true, - 'type' => 'option', - 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), - ) - ); - $wp_customize->add_setting( - 'featured-content[show-all]', - array( - 'default' => false, - 'type' => 'option', - 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), - ) - ); - - // Add Featured Content controls. - $wp_customize->add_control( - 'featured-content[tag-name]', - array( - 'label' => esc_html__( 'Tag name', 'jetpack' ), - 'section' => 'featured_content', - 'theme_supports' => 'featured-content', - 'priority' => 20, - ) - ); - $wp_customize->add_control( - 'featured-content[hide-tag]', - array( - 'label' => esc_html__( 'Do not display tag in post details and tag clouds.', 'jetpack' ), - 'section' => 'featured_content', - 'theme_supports' => 'featured-content', - 'type' => 'checkbox', - 'priority' => 30, - ) - ); - $wp_customize->add_control( - 'featured-content[show-all]', - array( - 'label' => esc_html__( 'Also display tagged posts outside the Featured Content area.', 'jetpack' ), - 'section' => 'featured_content', - 'theme_supports' => 'featured-content', - 'type' => 'checkbox', - 'priority' => 40, - ) - ); + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\customize_register' ); + Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::customize_register( $wp_customize ); } /** * Enqueue the tag suggestion script. + * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. */ public static function enqueue_scripts() { - wp_enqueue_script( 'featured-content-suggest', plugins_url( 'js/suggest.js', __FILE__ ), array( 'jquery', 'suggest' ), '20131022', true ); + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\enqueue_scripts' ); + Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::enqueue_scripts(); } /** * Renders all form fields on the Settings -> Reading screen. + * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. */ public static function render_form() { - printf( - wp_kses( - /* translators: %s: Link to the Featured Content settings in the Customizer. */ - __( 'The settings for Featured Content have moved to Appearance → Customize.', 'jetpack' ), - array( - 'a' => array( 'href' => array() ), - ) - ), - esc_url( admin_url( 'customize.php?#accordion-section-featured_content' ) ) - ); + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\render_form' ); + Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::render_form(); } /** @@ -621,46 +304,13 @@ public static function render_form() { * In the event that you only require one setting, you may pass its name as the * first parameter to the function and only that value will be returned. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @param string $key The key of a recognized setting. * @return mixed Array of all settings by default. A single value if passed as first parameter. */ public static function get_setting( $key = 'all' ) { - $saved = (array) get_option( 'featured-content' ); - - /** - * Filter Featured Content's default settings. - * - * @module theme-tools - * - * @since 2.7.0 - * - * @param array $args { - * Array of Featured Content Settings - * - * @type int hide-tag Default is 1. - * @type int tag-id Default is 0. - * @type string tag-name Default is empty. - * @type int show-all Default is 0. - * } - */ - $defaults = apply_filters( - 'featured_content_default_settings', - array( - 'hide-tag' => 1, - 'tag-id' => 0, - 'tag-name' => '', - 'show-all' => 0, - ) - ); - - $options = wp_parse_args( $saved, $defaults ); - $options = array_intersect_key( $options, $defaults ); - - if ( 'all' !== $key ) { - return isset( $options[ $key ] ) ? $options[ $key ] : false; - } - - return $options; + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\get_setting' ); + return Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::get_setting( $key ); } /** @@ -670,101 +320,42 @@ public static function get_setting( $key = 'all' ) { * saving to the database. This function will also delete the transient set in * Featured_Content::get_featured_content(). * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @uses Featured_Content::delete_transient() * * @param array $input Array of settings input. * @return array $output */ public static function validate_settings( $input ) { - $output = array(); - - if ( empty( $input['tag-name'] ) ) { - $output['tag-id'] = 0; - } else { - $term = get_term_by( 'name', $input['tag-name'], 'post_tag' ); - - if ( $term ) { - $output['tag-id'] = $term->term_id; - } else { - $new_tag = wp_create_tag( $input['tag-name'] ); - - if ( ! is_wp_error( $new_tag ) && isset( $new_tag['term_id'] ) ) { - $output['tag-id'] = $new_tag['term_id']; - } - } - - $output['tag-name'] = $input['tag-name']; - } - - $output['hide-tag'] = isset( $input['hide-tag'] ) && $input['hide-tag'] ? 1 : 0; - - $output['show-all'] = isset( $input['show-all'] ) && $input['show-all'] ? 1 : 0; - - self::delete_transient(); - - return $output; + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\validate_settings' ); + return Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::validate_settings( $input ); } /** * Removes the quantity setting from the options array. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @return void */ public static function switch_theme() { - $option = (array) get_option( 'featured-content' ); - - if ( isset( $option['quantity'] ) ) { - unset( $option['quantity'] ); - update_option( 'featured-content', $option ); - } + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\switch_theme' ); + Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::switch_theme(); } /** * Update Featured Content term data as necessary when a shared term is split. * + * @deprecated $$next-version$$ Moved to Classic Theme Helper package. * @param int $old_term_id ID of the formerly shared term. * @param int $new_term_id ID of the new term created for the $term_taxonomy_id. * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. * @param string $taxonomy Taxonomy for the split term. */ public static function jetpack_update_featured_content_for_split_terms( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { - $featured_content_settings = get_option( 'featured-content', array() ); - - // Check to see whether the stored tag ID is the one that's just been split. - if ( isset( $featured_content_settings['tag-id'] ) && $old_term_id == $featured_content_settings['tag-id'] && 'post_tag' === $taxonomy ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual - // We have a match, so we swap out the old tag ID for the new one and resave the option. - $featured_content_settings['tag-id'] = $new_term_id; - update_option( 'featured-content', $featured_content_settings ); - } + _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Featured_Content\\jetpack_update_featured_content_for_split_terms' ); + Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::jetpack_update_featured_content_for_split_terms( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy ); } } - /** - * Adds the featured content plugin to the set of files for which action - * handlers should be copied when the theme context is loaded by the REST API. - * - * @param array $copy_dirs Copy paths with actions to be copied. - * @return array Copy paths with featured content plugin - */ - function wpcom_rest_api_featured_content_copy_plugin_actions( $copy_dirs ) { - $copy_dirs[] = __FILE__; - return $copy_dirs; - } - add_action( 'restapi_theme_action_copy_dirs', 'wpcom_rest_api_featured_content_copy_plugin_actions' ); - - /** - * Delayed initialization for API Requests. - * - * @param object $request REST request object. - */ - function wpcom_rest_request_before_callbacks( $request ) { - Featured_Content::init(); - return $request; - } - - if ( Constants::is_true( 'IS_WPCOM' ) && Constants::is_true( 'REST_API_REQUEST' ) ) { - add_filter( 'rest_request_before_callbacks', 'wpcom_rest_request_before_callbacks' ); - } - - Featured_Content::setup(); + Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::setup(); } diff --git a/projects/plugins/mu-wpcom-plugin/changelog/update-move-featured-content-usage-from-module-to-package b/projects/plugins/mu-wpcom-plugin/changelog/update-move-featured-content-usage-from-module-to-package new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/mu-wpcom-plugin/changelog/update-move-featured-content-usage-from-module-to-package @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/mu-wpcom-plugin/changelog/update-move-featured-content-usage-from-module-to-package#2 b/projects/plugins/mu-wpcom-plugin/changelog/update-move-featured-content-usage-from-module-to-package#2 new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/mu-wpcom-plugin/changelog/update-move-featured-content-usage-from-module-to-package#2 @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/mu-wpcom-plugin/changelog/update-move-featured-content-usage-from-module-to-package#3 b/projects/plugins/mu-wpcom-plugin/changelog/update-move-featured-content-usage-from-module-to-package#3 new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/mu-wpcom-plugin/changelog/update-move-featured-content-usage-from-module-to-package#3 @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/mu-wpcom-plugin/changelog/update-move-featured-content-usage-from-module-to-package#4 b/projects/plugins/mu-wpcom-plugin/changelog/update-move-featured-content-usage-from-module-to-package#4 new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/mu-wpcom-plugin/changelog/update-move-featured-content-usage-from-module-to-package#4 @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/mu-wpcom-plugin/composer.lock b/projects/plugins/mu-wpcom-plugin/composer.lock index a0d1b5d8099e7..1caf76898eb1c 100644 --- a/projects/plugins/mu-wpcom-plugin/composer.lock +++ b/projects/plugins/mu-wpcom-plugin/composer.lock @@ -311,7 +311,7 @@ "dist": { "type": "path", "url": "../../packages/classic-theme-helper", - "reference": "4851293db36b3c568391618cd733ab7618c95ae6" + "reference": "0a0b72c656b3949e67db20779c1f8bab8d8426fb" }, "require": { "automattic/jetpack-assets": "@dev", @@ -329,7 +329,7 @@ "extra": { "autotagger": true, "branch-alias": { - "dev-trunk": "0.2.x-dev" + "dev-trunk": "0.3.x-dev" }, "changelogger": { "link-template": "https://github.com/Automattic/jetpack-classic-theme-helper/compare/v${old}...v${new}" @@ -337,7 +337,7 @@ "mirror-repo": "Automattic/jetpack-classic-theme-helper", "textdomain": "jetpack-classic-theme-helper", "version-constants": { - "::PACKAGE_VERSION": "src/class-classic-theme-helper.php" + "::PACKAGE_VERSION": "src/class-main.php" } }, "autoload": {