Skip to content

Commit

Permalink
Cleaned up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
sybrew committed Oct 21, 2020
1 parent 3cf00c9 commit a80b6dd
Show file tree
Hide file tree
Showing 42 changed files with 168 additions and 130 deletions.
9 changes: 5 additions & 4 deletions bootstrap/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function _init_locale( $ignore = false ) {
\load_plugin_textdomain(
'the-seo-framework-extension-manager',
false,
dirname( TSF_EXTENSION_MANAGER_PLUGIN_BASENAME ) . DIRECTORY_SEPARATOR . 'language'
\dirname( TSF_EXTENSION_MANAGER_PLUGIN_BASENAME ) . DIRECTORY_SEPARATOR . 'language'
);
}
}
Expand Down Expand Up @@ -89,6 +89,7 @@ function _protect_options() {
*/
function _pre_execute_protect_option( $new_value, $old_value, $option ) {

// phpcs:ignore, TSF.Performance.Functions.PHP -- required
if ( false === class_exists( 'TSF_Extension_Manager\SecureOption', true ) )
\wp_die( '<code>' . \esc_html( $option ) . '</code> is a protected option.' );

Expand Down Expand Up @@ -161,7 +162,7 @@ function _init_tsf_extension_manager() {
* @since 1.5.0
*/
\do_action( 'tsfem_extensions_initialized' );
} elseif ( ! function_exists( '\\the_seo_framework' ) ) {
} elseif ( ! \function_exists( '\\the_seo_framework' ) ) {
/**
* Nothing is loaded at this point; not even The SEO Framework.
*
Expand Down Expand Up @@ -192,7 +193,7 @@ function _register_autoloader() {
];

foreach ( $integrity_classes as $_class )
$iniquity = class_exists( $_class, false );
$iniquity = class_exists( $_class, false ); // phpcs:ignore, TSF.Performance.Functions.PHP -- required.
$iniquity and die;

/**
Expand Down Expand Up @@ -223,7 +224,7 @@ function can_load_class() {
if ( isset( $can_load ) )
return $can_load;

if ( function_exists( '\\the_seo_framework' ) ) {
if ( \function_exists( '\\the_seo_framework' ) ) {
if ( version_compare( THE_SEO_FRAMEWORK_VERSION, '4.0.5', '>=' ) && \the_seo_framework()->loaded )
return $can_load = (bool) \apply_filters( 'tsf_extension_manager_enabled', true );
}
Expand Down
12 changes: 6 additions & 6 deletions bootstrap/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function _prepare_tsf_installer() {
if ( ! \current_user_can( 'install_plugins' ) ) return;
if ( 'update.php' === $GLOBALS['pagenow'] ) return;

if ( ! function_exists( '\\get_plugins' ) )
if ( ! \function_exists( '\\get_plugins' ) )
require_once ABSPATH . 'wp-admin/includes/plugin.php';

$plugins = \get_plugins();
Expand Down Expand Up @@ -96,7 +96,7 @@ function _nag_install_tsf() {
'<a href="%1$s" id=tsfem-tsf-tb class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
\esc_url( $details_url ),
/* translators: %s: Plugin name */
\esc_attr( sprintf( __( 'Learn more about %s', 'the-seo-framework-extension-manager' ), $tsf_text ) ),
\esc_attr( sprintf( \__( 'Learn more about %s', 'the-seo-framework-extension-manager' ), $tsf_text ) ),
\esc_html__( 'View plugin details', 'the-seo-framework-extension-manager' )
);
$nag = sprintf(
Expand Down Expand Up @@ -227,22 +227,22 @@ function _hook_plugins_api( $res, $action, $args ) {
\esc_url( TSF_EXTENSION_MANAGER_DL_URI ),
'https://theseoframework.com/contact/'
);
$res = new WP_Error( 'plugins_api_failed',
$res = new \WP_Error( 'plugins_api_failed',
$error_message,
$request->get_error_message() // $data
);
} else {
$res = \maybe_unserialize( \wp_remote_retrieve_body( $request ) ); // phpcs:ignore -- No objects are sent.
if ( ! is_object( $res ) && ! is_array( $res ) ) {
$res = new WP_Error( 'plugins_api_failed',
if ( ! \is_object( $res ) && ! \is_array( $res ) ) {
$res = new \WP_Error( 'plugins_api_failed',
sprintf(
/* translators: %s: support forums URL */
\__( 'An unexpected error occurred. Something may be wrong with TheSEOFramework.com or this server&#8217;s configuration. If you continue to have problems, please <a href="%s">contact us</a>.', 'the-seo-framework-extension-manager' ),
'https://theseoframework.com/contact/'
),
\wp_remote_retrieve_body( $request )
);
} elseif ( is_array( $res ) ) {
} elseif ( \is_array( $res ) ) {
$res = (object) $res;
}
}
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/upgrader.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* @link https://bugs.php.net/bug.php?id=75771
*/
$_load_upgrader_class = function() {
new Upgrader();
new Upgrader(); // phpcs:ignore, TSF.Performance.Opcodes.ShouldHaveNamespaceEscape -- correct scope.
};

/**
Expand Down Expand Up @@ -384,7 +384,7 @@ private function yield_runs( \stdClass $upgrade ) {
*/
private function do_upgrade_cb( $version, callable $callback ) {
return [
'success' => (bool) call_user_func_array( $callback, [ $version ] ),
'success' => (bool) \call_user_func_array( $callback, [ $version ] ),
'version' => $version,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private function generate_post_type_settings() {
'_check' => [
\__( 'Enable article markup support?', 'the-seo-framework-extension-manager' ),
],
'_data' => [
'_data' => [
'is-type-listener' => '1',
'set-type-to-if-value' => [
'enabled' => '1',
Expand Down Expand Up @@ -405,7 +405,7 @@ public function _register_sanitization( $settings ) {
*/
public static function _sanitize_option_post_type( $value ) {

if ( ! is_array( $value ) )
if ( ! \is_array( $value ) )
$value = [];

$post_types = \the_seo_framework()->get_supported_post_types();
Expand Down Expand Up @@ -615,7 +615,7 @@ public function _prepare_bulk_views( $post_type, $taxonomy ) {
'type' => [
'label' => \__( 'Article Type', 'the-seo-framework-extension-manager' ),
'options' => [
'nochange' => __( '&mdash; No Change &mdash;', 'default' ),
'nochange' => \__( '&mdash; No Change &mdash;', 'default' ),
] + static::filter_article_keys( [
'disabled' => \__( '&mdash; Disabled &mdash;', 'the-seo-framework-extension-manager' ),
'Article' => \__( 'Article', 'the-seo-framework-extension-manager' ),
Expand Down
3 changes: 2 additions & 1 deletion extensions/essentials/cord/trunk/inc/classes/admin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function _register_sanitization( $settings ) {
*/
public static function _sanitize_options_analytics( $value ) {

if ( ! is_array( $value ) )
if ( ! \is_array( $value ) )
$value = [];

// TODO do we want to strip unknown entries from payload?
Expand Down Expand Up @@ -291,6 +291,7 @@ public static function _sanitize_options_analytics( $value ) {

case 'facebook_pixel':
$key = 'pixel_id';

$value[ $index ][ $key ] = trim( \tsf_extension_manager()->coalesce_var( $value[ $index ][ $key ], '' ) );
if ( ! preg_match( '/^[0-9]+$/', $value[ $index ][ $key ] ) ) {
$value[ $index ][ $key ] = '';
Expand Down
12 changes: 6 additions & 6 deletions extensions/essentials/focus/trunk/inc/classes/admin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ private function is_language_supported( $type ) {
$locale = substr( \get_locale(), 0, 2 );
$supported = false;

if ( in_array( $type, [ 'any', 'synonyms' ], true ) ) {
if ( \in_array( $type, [ 'any', 'synonyms' ], true ) ) {
$supported = 'en' === $locale;
}
if ( in_array( $type, [ 'any', 'inflections' ], true ) ) {
$supported = $supported || in_array( $locale, [ 'en', 'es', 'lv', 'hi', 'sw', 'ta', 'ro' ], true );
if ( \in_array( $type, [ 'any', 'inflections' ], true ) ) {
$supported = $supported || \in_array( $locale, [ 'en', 'es', 'lv', 'hi', 'sw', 'ta', 'ro' ], true );
}

return $supported;
Expand Down Expand Up @@ -340,7 +340,7 @@ private function process_meta( $post, $data ) {
default:
break;
}
if ( is_null( $store[ $key ] ) ) unset( $store[ $key ] );
if ( \is_null( $store[ $key ] ) ) unset( $store[ $key ] );
endforeach;

if ( empty( $store ) ) {
Expand All @@ -364,7 +364,7 @@ private function sanitize_keyword_data( array $values ) {
$output = [];
foreach ( $values as $id => $items ) {
//= Don't store when no keyword is set.
if ( ! isset( $items['keyword'] ) || ! strlen( $items['keyword'] ) )
if ( ! isset( $items['keyword'] ) || ! \strlen( $items['keyword'] ) )
continue;

foreach ( (array) $items as $key => $value ) {
Expand Down Expand Up @@ -416,7 +416,7 @@ private function sanitize_keyword_data_by_type( $type, $value ) {
break;

case 'scores':
if ( ! is_array( $value ) ) {
if ( ! \is_array( $value ) ) {
$value = [];
} else {
foreach ( $value as $_t => $_v ) {
Expand Down
10 changes: 5 additions & 5 deletions extensions/essentials/focus/trunk/inc/classes/ajax.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function _get_lexicalforms() {

$send = [];

if ( ! strlen( $keyword ) || ! $language ) {
if ( ! \strlen( $keyword ) || ! $language ) {
//= How in the...
$send['results'] = $this->get_ajax_notice( false, 1100101 );
} else {
Expand Down Expand Up @@ -181,7 +181,7 @@ public function _get_lexicalforms() {
} elseif ( ! isset( $response->data ) ) {
$send['results'] = $this->get_ajax_notice( false, 1100104 );
} else {
$_data = is_string( $response->data ) ? json_decode( $response->data ) : (object) $response->data;
$_data = \is_string( $response->data ) ? json_decode( $response->data ) : (object) $response->data;

if ( isset( $_data->forms ) ) {
$type = 'success'; // The API responded as intended, although the data may not be useful.
Expand Down Expand Up @@ -261,7 +261,7 @@ public function _get_inflections() {
} elseif ( ! isset( $response->data ) ) {
$send['results'] = $this->get_ajax_notice( false, 1100305 );
} else {
$_data = is_string( $response->data ) ? json_decode( $response->data ) : (object) $response->data;
$_data = \is_string( $response->data ) ? json_decode( $response->data ) : (object) $response->data;

if ( isset( $_data->inflections ) ) {
$type = 'success'; // The API responded as intended, although the data may not be useful.
Expand All @@ -271,7 +271,7 @@ public function _get_inflections() {
// When no inflections are returned, or if the one returned is only of the same kind as the keyword, fail.
// NOTE: Uses weak non-UTF8 strtolower. Users are smart enough to ignore useless data.
if ( ! $send['data']['inflections']
|| count( $send['data']['inflections'] ) < 2
|| \count( $send['data']['inflections'] ) < 2
&& strtolower( $send['data']['inflections'][0] ) === strtolower( $keyword ) ) {
$send['results'] = $this->get_ajax_notice( false, 1100306 );
} else {
Expand Down Expand Up @@ -346,7 +346,7 @@ public function _get_synonyms() {
} elseif ( ! isset( $response->data ) ) {
$send['results'] = $this->get_ajax_notice( false, 1100204 );
} else {
$_data = is_string( $response->data ) ? json_decode( $response->data ) : (object) $response->data;
$_data = \is_string( $response->data ) ? json_decode( $response->data ) : (object) $response->data;

if ( isset( $_data->synonyms ) ) {
$type = 'success'; // The API responded as intended, although the data may not be useful.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function get_nearest_numeric_index_value( array $a, $value ) {
*/
public function get_data_attributes( $type ) {
return \TSF_Extension_Manager\HTML::make_data_attributes( [
'scores' => \tsf_extension_manager()->filter_keys(
'scores' => \tsf_extension_manager()->filter_keys(
$this->get_template( $type ),
[ 'assessment', 'maxScore', 'minScore', 'phrasing', 'rating', 'scoring' ]
),
Expand Down
2 changes: 1 addition & 1 deletion extensions/free/amp/trunk/amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function _amp_init() {
} else {
$is_amp = false;

if ( function_exists( '\\is_amp_endpoint' ) ) {
if ( \function_exists( '\\is_amp_endpoint' ) ) {
$is_amp = \is_amp_endpoint();
} elseif ( \defined( 'AMP_QUERY_VAR' ) ) {
$is_amp = \get_query_var( AMP_QUERY_VAR, false ) !== false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private function should_change_precision() {
if ( isset( $cache ) )
return $cache;

$precision = function_exists( 'ini_get' ) ? ini_get( 'serialize_precision' ) : null;
$precision = \function_exists( 'ini_get' ) ? ini_get( 'serialize_precision' ) : null;

//= -1 means it's optimized correctly. 7 to 14 would also do, actually.
if ( isset( $precision ) && -1 !== (int) $precision )
Expand All @@ -75,7 +75,7 @@ private function can_change_precision() {
if ( isset( $cache ) )
return $cache;

if ( ! function_exists( 'ini_get_all' ) )
if ( ! \function_exists( 'ini_get_all' ) )
return $cache = false;

$ini_all = ini_get_all();
Expand Down Expand Up @@ -151,7 +151,7 @@ protected function get_schema() {
$schema_file = TSFEM_E_LOCAL_DIR_PATH . 'lib' . DIRECTORY_SEPARATOR . 'schema' . DIRECTORY_SEPARATOR . 'schema.json';
$timeout = stream_context_create( [ 'http' => [ 'timeout' => 3 ] ] );

// phpcs:ignore, WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- This isn't a remote call.
// phpcs:ignore, WordPress.WP.AlternativeFunctions, TSF.Performance.Functions -- This isn't a remote call; required.
return json_decode( file_get_contents( $schema_file, false, $timeout ) );
}

Expand All @@ -170,7 +170,7 @@ protected function pack_data( array $data, $pretty = false ) {

$schema = $this->get_schema();

if ( ! is_object( $schema ) )
if ( ! \is_object( $schema ) )
return '';

$this->correct_precision();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function _do_ajax_form_save() {
* If this page doesn't parse the site options,
* there's no need to check them on each request.
*/
if ( ! is_array( $data[ TSF_EXTENSION_MANAGER_EXTENSION_OPTIONS ][ $this->o_index ] ) ) {
if ( ! \is_array( $data[ TSF_EXTENSION_MANAGER_EXTENSION_OPTIONS ][ $this->o_index ] ) ) {
$type = 'failure';
$send['results'] = $this->get_ajax_notice( false, 1070100 );
} else {
Expand Down Expand Up @@ -198,7 +198,7 @@ public function _init_ajax_iteration_callback() {
if ( $key ) {
$method = $this->get_iterator_callback_by_key( $key );
if ( $method ) {
$fields = &\TSF_Extension_Manager\FormGenerator::_collect_ajax_its_fields();
$fields = &\TSF_Extension_Manager\FormGenerator::_collect_ajax_its_fields(); // phpcs:ignore -- collector, wrong assessment.
$fields = Fields::get_instance()->{$method}();
}
}
Expand Down Expand Up @@ -284,7 +284,7 @@ private function send_ajax_form_json_validation() {
*/
if ( empty( $data )
|| ( ! isset( $data[ TSF_EXTENSION_MANAGER_EXTENSION_OPTIONS ][ $this->o_index ] ) )
|| ( ! is_array( $data[ TSF_EXTENSION_MANAGER_EXTENSION_OPTIONS ][ $this->o_index ] ) )
|| ( ! \is_array( $data[ TSF_EXTENSION_MANAGER_EXTENSION_OPTIONS ][ $this->o_index ] ) )
) {
$type = 'failure';
$send['results'] = $this->get_ajax_notice( false, 1070200 );
Expand Down
3 changes: 1 addition & 2 deletions extensions/premium/local/trunk/views/layout/general/top.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
<?php
$image = [
'svg' => TSFEM_E_LOCAL_DIR_URL . 'lib/images/icon.svg',
// '2x' => TSFEM_E_LOCAL_DIR_URL . 'lib/images/icon-58x58.png',
'1x' => TSFEM_E_LOCAL_DIR_URL . 'lib/images/icon-29x29px.png',
'1x' => TSFEM_E_LOCAL_DIR_URL . 'lib/images/icon-29x29px.png',
];
$size = '1em';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<?php
$image = [
'svg' => TSFEM_E_MONITOR_DIR_URL . 'lib/images/icon.svg',
// '2x' => TSFEM_E_MONITOR_DIR_URL . 'lib/images/icon-58x58.png',
'1x' => TSFEM_E_MONITOR_DIR_URL . 'lib/images/icon-29x29px.png',
];
$size = '1em';
Expand Down
6 changes: 3 additions & 3 deletions inc/classes/abstract/secure.abstract.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ final private static function reset_instance() {

foreach ( $class_vars as $property => $value ) :
if ( isset( self::$$property ) )
self::$$property = is_array( self::$$property ) ? [] : null;
self::$$property = \is_array( self::$$property ) ? [] : null;
endforeach;
}

Expand Down Expand Up @@ -241,7 +241,7 @@ final protected static function is_premium_user() {

$level = isset( self::$account['level'] ) ? self::$account['level'] : '';

return $is_premium = in_array( $level, [ 'Enterprise', 'Premium' ], true );
return $is_premium = \in_array( $level, [ 'Enterprise', 'Premium' ], true );
}

/**
Expand All @@ -261,7 +261,7 @@ final protected static function is_connected_user() {

$level = isset( self::$account['level'] ) ? self::$account['level'] : '';

return $is_connected = in_array( $level, [ 'Enterprise', 'Premium', 'Essentials' ], true );
return $is_connected = \in_array( $level, [ 'Enterprise', 'Premium', 'Essentials' ], true );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions inc/classes/adminpages.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ final public function _add_menu_link() {
];

if ( \TSF_Extension_Manager\can_do_manager_settings() ) {
$notice_count = count( \get_option( $this->error_notice_option, false ) ?: [] );
$notice_count = \count( \get_option( $this->error_notice_option, false ) ?: [] );
} else {
$notice_count = 0;
}
Expand All @@ -144,7 +144,7 @@ final public function _add_menu_link() {
$notice_i18n = \number_format_i18n( $notice_count );
$notice_text = sprintf(
/* translators: %s: number of notices waiting */
_n( '%s notice waiting', '%s notices waiting', $notice_count, 'the-seo-framework-extension-manager' ),
\_n( '%s notice waiting', '%s notices waiting', $notice_count, 'the-seo-framework-extension-manager' ),
$notice_i18n
);

Expand Down Expand Up @@ -184,7 +184,7 @@ final public function load_menu_notice_styles() {
* 'midnight' should also be excluded, but that's messed up on another level.
* Let's just say we got this mildly accurate on 6 out of 8 schemes.
*/
$inline = in_array( $_scheme, [ 'fresh', 'light', 'blue' ], true ) ? null : [
$inline = \in_array( $_scheme, [ 'fresh', 'light', 'blue' ], true ) ? null : [
'#adminmenu .tsfem-menu-notice' => [
'background-color:{{$color_accent}}',
'color:{{$rel_color_accent}}',
Expand Down
Loading

0 comments on commit a80b6dd

Please sign in to comment.