Skip to content

Commit

Permalink
Fixes for PHP 8.2 (#156)
Browse files Browse the repository at this point in the history
* Fix dynamic properties declaration

* fix spacing

* Fix calling trait outside class

* More fixes

* More fixes

* More fixes

* More fixes

* More fixes

* More fixes

* Update dependencies

* More fixes

* Version bump

---------

Co-authored-by: xxsimoxx <[email protected]>
  • Loading branch information
xxsimoxx and xxsimoxx authored Jul 6, 2023
1 parent ea869c4 commit 5128931
Show file tree
Hide file tree
Showing 40 changed files with 731 additions and 218 deletions.
4 changes: 2 additions & 2 deletions classicpress-seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Classic SEO
* Plugin URI: https://github.com/ClassicPress/classicpress-seo
* Description: Classic SEO is the first SEO plugin built specifically to work with ClassicPress. The plugin contains many essential SEO tools to help optimize your website.
* Version: 2.1.3
* Version: 2.2.0.alpha.0
* Author: ClassicPress
* Author URI: https://github.com/ClassicPress
* License: GPL v2 or later
Expand Down Expand Up @@ -34,7 +34,7 @@ class Classic_SEO {
*
* @var string
*/
public $version = '2.1.3';
public $version = '2.2.0';

/**
* Classic SEO database version.
Expand Down
21 changes: 14 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions includes/admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
class Admin implements Runner {

use Hooker, Ajax;
use Hooker, Ajax, Conditional;

/**
* Register hooks.
Expand Down Expand Up @@ -113,7 +113,7 @@ public function canonical_check_notice( $post_id ) {
$post_type = get_post_type( $post_id );
$is_allowed = in_array( $post_type, Helper::get_allowed_post_types(), true );

if ( ! $is_allowed || Conditional::is_autosave() || Conditional::is_ajax() || isset( $_REQUEST['bulk_edit'] ) ) {
if ( ! $is_allowed || Admin::is_autosave() || Admin::is_ajax() || isset( $_REQUEST['bulk_edit'] ) ) {
return $post_id;
}

Expand Down
1 change: 1 addition & 0 deletions includes/admin/class-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/**
* Options class.
*/
#[\AllowDynamicProperties]
class Options {

use Hooker;
Expand Down
6 changes: 4 additions & 2 deletions includes/class-cmb2.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
class CMB2 {

use Conditional;

/**
* Set field arguments based on type.
*
Expand Down Expand Up @@ -99,7 +101,7 @@ public static function current_object_type() {
$type = 'term';
}

if ( Conditional::is_ajax() && 'add-tag' === Param::post( 'action' ) ) {
if ( CMB2::is_ajax() && 'add-tag' === Param::post( 'action' ) ) {
$type = 'term';
}

Expand Down Expand Up @@ -313,7 +315,7 @@ public static function sanitize_webmaster_tags( $value ) {

return $value;
}

/**
* Handles sanitization of advanced robots data.
*
Expand Down
4 changes: 2 additions & 2 deletions includes/class-installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
class Installer {

use Hooker;
use Hooker, WordPress;

/**
* Bind all events.
Expand Down Expand Up @@ -574,7 +574,7 @@ private function get_opening_hours() {
* @return array
*/
private function get_excluded_roles() {
$roles = WordPress::get_roles();
$roles = Installer::get_roles();
unset( $roles['administrator'], $roles['editor'], $roles['author'] );

return $roles;
Expand Down
3 changes: 2 additions & 1 deletion includes/class-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/**
* Metadata class.
*/
#[\AllowDynamicProperties]
abstract class Metadata {

/**
Expand Down Expand Up @@ -132,7 +133,7 @@ public function maybe_replace_vars( $key, $value, $object ) {
if ( ! in_array( $key, $need_replacements, true ) || ! is_string( $value ) || '' === $value ) {
return false;
}

$value = \str_replace( [ '%seo_title%', '%seo_description%' ], [ '%title%', '%excerpt%' ], $value );

return Helper::replace_vars( $value, $object );
Expand Down
4 changes: 3 additions & 1 deletion includes/class-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
class Post extends Metadata {

use Conditional;

/**
* Type of object metadata is for (e.g., comment, post, or user).
*
Expand Down Expand Up @@ -168,7 +170,7 @@ public static function is_shop_page() {
* @return bool Whether the current page is a WooCommerce page.
*/
public static function is_woocommerce_page() {
if ( Conditional::is_woocommerce_active() || Conditional::is_classic_commerce_active() ) {
if ( Post::is_woocommerce_active() || Post::is_classic_commerce_active() ) {
return \is_cart() || \is_checkout() || \is_account_page();
}

Expand Down
1 change: 1 addition & 0 deletions includes/frontend/class-add-attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/**
* Add Attributes class.
*/
#[\AllowDynamicProperties]
class Add_Attributes {

use Hooker;
Expand Down
28 changes: 15 additions & 13 deletions includes/helpers/class-conditional.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* Conditional class.
*/
trait Conditional {


use WordPress;

/**
* Check if whitelabel filter is active.
*
Expand All @@ -43,7 +45,7 @@ public static function is_whitelabel() {
public static function is_ajax() {
return function_exists( 'wp_doing_ajax' ) ? wp_doing_ajax() : defined( 'DOING_AJAX' ) && DOING_AJAX;
}

/**
* Is CRON request
*
Expand All @@ -52,7 +54,7 @@ public static function is_ajax() {
public static function is_cron() {
return function_exists( 'wp_doing_cron' ) ? wp_doing_cron() : defined( 'DOING_CRON' ) && DOING_CRON;
}

/**
* Is auto-saving
*
Expand All @@ -61,7 +63,7 @@ public static function is_cron() {
public static function is_autosave() {
return defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE;
}

/**
* Is REST request
*
Expand Down Expand Up @@ -103,8 +105,8 @@ public static function is_rest() {
0 === strpos( $current_url['path'], $rest_url['path'], 0 )
);
}


/**
* Check if module is active.
*
Expand Down Expand Up @@ -135,7 +137,7 @@ public static function is_configured( $value = null ) {
Helper::schedule_flush_rewrite();
update_option( $key, $value );
}

/**
* Check if the site is connected to the Classic SEO API.
*
Expand Down Expand Up @@ -187,7 +189,7 @@ public static function is_score_enabled() {
*/
return apply_filters( 'cpseo/show_score', true );
}

/**
* Check if the request is heartbeat.
*
Expand All @@ -196,7 +198,7 @@ public static function is_score_enabled() {
public static function is_heartbeat() {
return 'heartbeat' === Param::post( 'action' );
}

/**
* Check if the request is from frontend.
*
Expand All @@ -215,22 +217,22 @@ public function is_frontend() {
*/
public static function is_woocommerce_active() {
// @codeCoverageIgnoreStart
$wp_filesystem = WordPress::get_filesystem();
$wp_filesystem = self::get_filesystem();

if ( ! function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}

/**
* Check for additional proof that the real WC is installed and not the Classic Commerce compatibility plugin
* Check for additional proof that the real WC is installed and not the Classic Commerce compatibility plugin
*/
if( $wp_filesystem->exists( WP_PLUGIN_DIR . "/woocommerce/includes/class-woocommerce.php" ) && $wp_filesystem->exists( WP_PLUGIN_DIR . "/woocommerce/includes/admin/class-wc-admin.php" ) ) {
// @codeCoverageIgnoreEnd
return in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
}
return false;
}

/**
* Is Classic Commerce Installed
*
Expand Down
2 changes: 1 addition & 1 deletion includes/helpers/class-wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private static function get_role_capabilities( $slug, $caps, &$data ) {
}
}
}

/**
* Set capabilities to role.
*
Expand Down
2 changes: 1 addition & 1 deletion includes/metaboxes/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
* @param bool $return True to disable.
*/
if ( false === $this->do_filter( 'primary_term', false ) ) {
$taxonomies = Helper::get_object_taxonomies( WordPress::get_post_type(), 'objects' );
$taxonomies = Helper::get_object_taxonomies( ( new class { use Wordpress; } )::get_post_type(), 'objects' );
$taxonomies = wp_filter_object_list( $taxonomies, array( 'hierarchical' => true ), 'and', 'name' );
foreach ( $taxonomies as $taxonomy ) {
$cmb->add_field( array(
Expand Down
1 change: 1 addition & 0 deletions includes/module/class-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/**
* Base class.
*/
#[\AllowDynamicProperties]
class Base {

use Hooker;
Expand Down
10 changes: 5 additions & 5 deletions includes/module/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class Manager {

use Hooker;
use Hooker, Conditional;

/**
* Holds modules.
Expand All @@ -40,7 +40,7 @@ class Manager {
* The Constructor.
*/
public function __construct() {
if ( Conditional::is_heartbeat() ) {
if ( Manager::is_heartbeat() ) {
return;
}

Expand Down Expand Up @@ -193,7 +193,7 @@ public function setup_3rd_party( $modules ) {
'disabled_text' => esc_html__( 'Please activate ' . $ecom . ' plugin to use this module.', 'cpseo' ),
];
}

if ( class_exists( 'ACF' ) ) {
$modules['acf'] = [
'title' => esc_html__( 'ACF', 'cpseo' ),
Expand Down Expand Up @@ -244,9 +244,9 @@ public function display_form() {
<div class="col">

<div class="cpseo-box <?php echo $is_active ? 'active' : ''; ?>">

<p style="float:right"><?php $module->the_link(); ?></p>

<span class="dashicons <?php echo $module->get_icon(); ?>"></span>

<header>
Expand Down
5 changes: 3 additions & 2 deletions includes/modules/404-monitor/class-monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
/**
* Monitor class.
*/
#[\AllowDynamicProperties]
class Monitor {

use Hooker, Ajax;
use Hooker, Ajax, Conditional;

/**
* The Constructor.
Expand All @@ -37,7 +38,7 @@ public function __construct() {
$this->admin = new Admin;
}

if ( Conditional::is_ajax() ) {
if ( Monitor::is_ajax() ) {
$this->ajax( 'delete_log', 'delete_log' );
}

Expand Down
6 changes: 3 additions & 3 deletions includes/modules/redirections/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
class Admin extends Base {

use Ajax, Hooker;
use Ajax, Hooker, Conditional, WordPress;

/**
* The Constructor.
Expand Down Expand Up @@ -89,7 +89,7 @@ private function load_metabox() {
* Hooks for ajax.
*/
private function ajax_hooks() {
if ( ! Conditional::is_ajax() ) {
if ( ! Admin::is_ajax() ) {
return;
}

Expand Down Expand Up @@ -185,7 +185,7 @@ public function init() {
return;
}

$action = WordPress::get_request_action();
$action = Admin::get_request_action();
if ( false === $action || empty( $_REQUEST['redirection'] ) || 'edit' === $action ) {
return;
}
Expand Down
Loading

0 comments on commit 5128931

Please sign in to comment.