From 12d36ccb2d9280a3383e04ef6e4deaf4c83f87b4 Mon Sep 17 00:00:00 2001 From: fumikito Date: Tue, 27 Aug 2024 23:17:56 +0900 Subject: [PATCH 1/8] =?UTF-8?q?#133=20deprecated=20notice=E3=82=92?= =?UTF-8?q?=E6=B6=88=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Gianism/Service/AbstractService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Gianism/Service/AbstractService.php b/app/Gianism/Service/AbstractService.php index c8cdfe0..ae83b9c 100644 --- a/app/Gianism/Service/AbstractService.php +++ b/app/Gianism/Service/AbstractService.php @@ -17,6 +17,7 @@ * @property-read string $service_name * @property-read bool $enabled */ +#[\AllowDynamicProperties] abstract class AbstractService extends Application { /** From b13ea29304236f8584099ed8a47755762ea1ee63 Mon Sep 17 00:00:00 2001 From: fumikito Date: Wed, 28 Aug 2024 12:13:33 +0900 Subject: [PATCH 2/8] #133 Escape URL with invalid prefix to avoid XSS --- templates/setting/google.php | 2 +- templates/setting/line.php | 2 +- templates/setting/twitter.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/setting/google.php b/templates/setting/google.php index f592a51..5a1d54c 100644 --- a/templates/setting/google.php +++ b/templates/setting/google.php @@ -37,7 +37,7 @@

get_redirect_endpoint(); + $end_point = esc_url( $instance->get_redirect_endpoint() ); printf( // translators: %1$s is redirect URI, %2$s is Google API Console, %3$s is link to Google API Console. __( 'Please set %1$s to %2$s on %3$s.', 'wp-gianism' ), diff --git a/templates/setting/line.php b/templates/setting/line.php index c54306a..9539264 100644 --- a/templates/setting/line.php +++ b/templates/setting/line.php @@ -47,7 +47,7 @@

get_redirect_endpoint(); + $end_point = esc_url( $instance->get_redirect_endpoint() ); printf( // translators: %1$s is callback URL, %2$s is link to LINE developer page, %3$s is link label, %4$s is link to LINE developer console. __( 'Please set %1$s to %2$s on %3$s.', 'wp-gianism' ), diff --git a/templates/setting/twitter.php b/templates/setting/twitter.php index 8ad8c63..2d3f50e 100644 --- a/templates/setting/twitter.php +++ b/templates/setting/twitter.php @@ -48,7 +48,7 @@

get_redirect_endpoint(); + $end_point = esc_url( $instance->get_redirect_endpoint() ); printf( __( 'Please set %1$s to %2$s on %3$s.', 'wp-gianism' ), __( 'Callback URL', 'wp-gianism' ), From a3082a8800ac0f93a3dd2911943ef0815c2a35dc Mon Sep 17 00:00:00 2001 From: fumikito Date: Wed, 28 Aug 2024 14:33:31 +0900 Subject: [PATCH 3/8] Fix lint --- app/Gianism/Api/Ga.php | 2 +- app/Gianism/Api/ShortCodes.php | 2 +- app/Gianism/Commands/CommandSkeleton.php | 1 - app/Gianism/Commands/TestCommand.php | 4 ++ app/Gianism/Controller/Admin.php | 2 +- app/Gianism/Controller/Login.php | 8 +-- app/Gianism/Controller/ProfileChecker.php | 18 ++++--- app/Gianism/Controller/Rewrite.php | 16 +++--- app/Gianism/Helper/Input.php | 10 ++-- app/Gianism/Helper/MessageHelper.php | 10 ++-- app/Gianism/Helper/Monitor.php | 2 - app/Gianism/Helper/Option.php | 11 ++-- app/Gianism/Helper/ServiceManager.php | 4 +- app/Gianism/Helper/Session.php | 2 - app/Gianism/Pattern/AbstractController.php | 1 - app/Gianism/Pattern/AbstractNotice.php | 1 - app/Gianism/Pattern/AppBase.php | 7 +-- app/Gianism/Pattern/Application.php | 1 - app/Gianism/Pattern/Singleton.php | 1 - app/Gianism/Plugins/Analytics.php | 15 +++--- app/Gianism/Plugins/AnalyticsFetcher.php | 17 +++---- app/Gianism/Plugins/Bot.php | 20 ++++---- app/Gianism/Plugins/PluginBase.php | 2 - app/Gianism/Service/AbstractService.php | 59 ++++++++++++---------- app/Gianism/Service/Facebook.php | 39 +++++++------- app/Gianism/Service/Google.php | 7 +-- app/Gianism/Service/Line.php | 10 ++-- app/Gianism/Service/NoMailService.php | 5 +- app/Gianism/Service/Twitter.php | 20 ++++---- app/Gianism/UI/Screen.php | 17 ++++--- composer.json | 2 +- functions-deprecated.php | 12 ++--- functions.php | 2 +- functions/facebook.php | 1 - functions/twitter.php | 29 ++++++----- hooks/simple-membership.php | 2 +- phpcs.ruleset.xml | 6 ++- templates/analytics.php | 24 ++++----- templates/edit/bot.php | 16 +++--- templates/fb-api.php | 25 +++++---- templates/parts/footer.php | 2 +- templates/parts/header.php | 4 +- templates/parts/sidebar.php | 14 ++--- templates/setting/facebook.php | 11 ++-- templates/setting/twitter.php | 22 +++++--- templates/setup/facebook.php | 15 +++--- templates/setup/line.php | 16 ++++-- wp-gianism.php | 6 +-- 48 files changed, 280 insertions(+), 243 deletions(-) diff --git a/app/Gianism/Api/Ga.php b/app/Gianism/Api/Ga.php index 098c05f..9386cb4 100644 --- a/app/Gianism/Api/Ga.php +++ b/app/Gianism/Api/Ga.php @@ -52,7 +52,7 @@ protected function start_date() { if ( preg_match( '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $this->input->get( 'from' ) ) ) { return $this->input->get( 'from' ); } else { - return date_i18n( 'Y-m-d', strtotime( '1 month ago', current_time( 'timestamp' ) ) ); + return date_i18n( 'Y-m-d', strtotime( '1 month ago', time() ) ); } } diff --git a/app/Gianism/Api/ShortCodes.php b/app/Gianism/Api/ShortCodes.php index 496ea0a..2423b65 100644 --- a/app/Gianism/Api/ShortCodes.php +++ b/app/Gianism/Api/ShortCodes.php @@ -2,7 +2,7 @@ namespace Gianism\Api; -use \Gianism\Pattern\Application; +use Gianism\Pattern\Application; /** * Short code API diff --git a/app/Gianism/Commands/CommandSkeleton.php b/app/Gianism/Commands/CommandSkeleton.php index b78ef6c..6404bf0 100644 --- a/app/Gianism/Commands/CommandSkeleton.php +++ b/app/Gianism/Commands/CommandSkeleton.php @@ -13,5 +13,4 @@ class CommandSkeleton extends \WP_CLI_Command { use AppBase; - } diff --git a/app/Gianism/Commands/TestCommand.php b/app/Gianism/Commands/TestCommand.php index a747d13..df66199 100644 --- a/app/Gianism/Commands/TestCommand.php +++ b/app/Gianism/Commands/TestCommand.php @@ -40,6 +40,7 @@ public function tweet( $args, $assoc ) { \WP_CLI::error( sprintf( '%s: %s', $tweet->get_error_code(), $tweet->get_error_message() ) ); } print_r( $tweet ); + // translators: %s is screen name. \WP_CLI::success( sprintf( __( 'Tweet has been sent as %s. Response message is above.', 'wp-gianism' ), $twitter->tw_screen_name ) ); } @@ -102,6 +103,7 @@ public function mentions( $args, $assoc ) { \WP_CLI::line( '' ); } } + // translators: %d is number of response. \WP_CLI::success( sprintf( _x( 'Got %d response.', 'CLI', 'wp-gianism' ), count( $response ) ) ); } @@ -121,6 +123,7 @@ public function analytics( $args, $assoc ) { $from = isset( $assoc['from'] ) ? $assoc['from'] : date_i18n( 'Y-m-d', strtotime( '7 days ago' ) ); $to = isset( $assoc['to'] ) ? $assoc['to'] : date_i18n( 'Y-m-d', strtotime( 'Yesterday' ) ); try { + // translators: %1$s and %2$s are date string. \WP_CLI::line( sprintf( __( 'Get popular pages from %1$s to %2$s.', 'wp-gianism' ), $from, $to ) ); $table = new Table(); $table->setHeaders( [ 'Page Path', 'PV' ] ); @@ -214,6 +217,7 @@ public function fb_instant_articles( $args, $assoc ) { $next_page = $edge->getCursor( 'after' ); $line = __( 'Successfully retrieved instant articles!', 'wp-gianism' ); if ( $next_page ) { + // translators: %s is next page id. \WP_CLI::success( $line . ' ' . sprintf( __( 'If you need more instant articles, set --after=%s', 'wp-gianism' ), $next_page ) ); } else { \WP_CLI::success( $line ); diff --git a/app/Gianism/Controller/Admin.php b/app/Gianism/Controller/Admin.php index d18c513..9ccd938 100644 --- a/app/Gianism/Controller/Admin.php +++ b/app/Gianism/Controller/Admin.php @@ -148,7 +148,7 @@ public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $stat if ( preg_match( '#href="https://gianism.info"#', $value ) ) { $plugin_meta[ $index ] = preg_replace_callback( '#href="https://gianism.info"#', - function( $matches ) { + function ( $matches ) { return sprintf( 'href="%s"', esc_url( diff --git a/app/Gianism/Controller/Login.php b/app/Gianism/Controller/Login.php index 8af9abb..a2c36bf 100644 --- a/app/Gianism/Controller/Login.php +++ b/app/Gianism/Controller/Login.php @@ -92,8 +92,11 @@ public function login_form( $before = '', $after = '', $register = false, $redir if ( empty( $after ) ) { $after = ''; } - if ( '' === $redirect_to && ( $redirect_query = $this->input->get( 'redirect_to' ) ) ) { - $redirect_to = $redirect_query; + if ( '' === $redirect_to ) { + $redirect_query = $this->input->get( 'redirect_to' ); + if ( $redirect_query ) { + $redirect_to = $redirect_query; + } } echo $before; /** @@ -151,5 +154,4 @@ public function woo_form() { } $this->login_form( '', '', false, $redirect, 'woo-account' ); } - } diff --git a/app/Gianism/Controller/ProfileChecker.php b/app/Gianism/Controller/ProfileChecker.php index 018a491..9026e2a 100644 --- a/app/Gianism/Controller/ProfileChecker.php +++ b/app/Gianism/Controller/ProfileChecker.php @@ -15,13 +15,13 @@ public function __construct( array $argument = [] ) { add_action( 'rest_api_init', [ $this, 'register_rest' ] ); add_action( 'init', - function() { + function () { if ( ! is_user_logged_in() ) { return; } add_action( 'template_redirect', - function() { + function () { if ( $this->should_redirect() ) { $this->redirect(); } elseif ( $this->should_show_popup() ) { @@ -69,8 +69,11 @@ public function should_redirect() { */ public function default_url() { $url = get_edit_profile_url(); - if ( gianism_woocommerce_detected() && ( $page = wc_get_page_permalink( 'myaccount' ) ) ) { - $url = get_permalink( $page ); + if ( gianism_woocommerce_detected() ) { + $page = wc_get_page_permalink( 'myaccount' ); + if ( $page ) { + $url = get_permalink( $page ); + } } return $url; } @@ -122,10 +125,10 @@ public function register_rest() { [ 'methods' => 'GET', 'args' => [], - 'permission_callback' => function() { + 'permission_callback' => function () { return is_user_logged_in(); }, - 'callback' => function( \WP_REST_Request $request ) { + 'callback' => function ( \WP_REST_Request $request ) { $error = $this->get_error( get_current_user_id() ); $response = [ 'errors' => $error->get_error_messages(), @@ -192,6 +195,7 @@ public function show_popup() { if ( ! $error->get_error_messages() ) { return; } + // translators: %s is URL $message = sprintf( __( 'You have an incomplete profile. To access full features of this site, please fill your profile here.', 'wp-gianism' ), $this->redirect_url() ); $message = apply_filters( 'gianism_profile_error_popup', $message, $this->redirect_url(), $error ); $this->add_message( $message, true ); @@ -211,7 +215,7 @@ public function is_excluded_paths( $path, $excluded = null ) { } $patterns = array_filter( array_map( - function( $line ) { + function ( $line ) { return trim( $line ); }, preg_split( '#[\r\n]#u', $excluded ) diff --git a/app/Gianism/Controller/Rewrite.php b/app/Gianism/Controller/Rewrite.php index 505da3a..c743675 100644 --- a/app/Gianism/Controller/Rewrite.php +++ b/app/Gianism/Controller/Rewrite.php @@ -133,7 +133,7 @@ public function rewrite_rules_array( array $rules ) { public function check_rewrite() { $registered_rewrites = $this->option->get( 'rewrite_rules' ); foreach ( $this->rewrites as $reg => $replaced ) { - if ( ! isset( $registered_rewrites[ $reg ] ) || $replaced != $registered_rewrites[ $reg ] ) { + if ( ! isset( $registered_rewrites[ $reg ] ) || $replaced !== $registered_rewrites[ $reg ] ) { flush_rewrite_rules(); } } @@ -145,10 +145,9 @@ public function check_rewrite() { * @param \WP_Query $wp_query */ public function hijack_query( \WP_Query &$wp_query ) { - if ( ! is_admin() && $wp_query->is_main_query() - && ( $service = $wp_query->get( 'gianism_service' ) ) - && ( $action = $wp_query->get( 'gianism_action' ) ) - ) { + $service = $wp_query->get( 'gianism_service' ); + $action = $wp_query->get( 'gianism_action' ); + if ( ! is_admin() && $wp_query->is_main_query() && $service && $action ) { /** * Convert rewrite rule to service name * @@ -158,17 +157,14 @@ public function hijack_query( \WP_Query &$wp_query ) { * @return string */ $filtered_service = apply_filters( 'gianism_filter_service_prefix', $service ); - if ( false !== array_search( $service, $this->prefixes ) && ( $instance = $this->service->get( $filtered_service ) ) ) { + if ( in_array( $service, $this->prefixes, true ) && ( $this->service->get( $filtered_service ) ) ) { nocache_headers(); /** @var AbstractService $instance */ // Parse Request - $instance->parse_request( $action, $wp_query ); + $this->service->get( $filtered_service )->parse_request( $action, $wp_query ); } else { $wp_query->set_404(); } } } - - - } diff --git a/app/Gianism/Helper/Input.php b/app/Gianism/Helper/Input.php index eaeda4b..6bfb073 100644 --- a/app/Gianism/Helper/Input.php +++ b/app/Gianism/Helper/Input.php @@ -94,19 +94,19 @@ public function nonce_action( $action ) { } /** - * Short hand for wp_die + * Shorthand for wp_die * * @param string $message - * @param int $status_code - * @param bool $return + * @param int $status_code + * @param bool $return_link */ - public function wp_die( $message, $status_code = 500, $return = true ) { + public function wp_die( $message, $status_code = 500, $return_link = true ) { wp_die( $message, get_status_header_desc( $status_code ) . ' | ' . get_bloginfo( 'name' ), [ 'response' => (int) $status_code, - 'back_link' => (bool) $return, + 'back_link' => (bool) $return_link, ] ); } diff --git a/app/Gianism/Helper/MessageHelper.php b/app/Gianism/Helper/MessageHelper.php index ca41dfe..454a025 100644 --- a/app/Gianism/Helper/MessageHelper.php +++ b/app/Gianism/Helper/MessageHelper.php @@ -13,17 +13,17 @@ trait MessageHelper { /** * Add message to show * - * @param string $string - * @param bool $error + * @param string $text + * @param bool $error * @return bool */ - protected function add_message( $string, $error = false ) { + protected function add_message( $text, $error = false ) { $key = 'gianism_' . ( $error ? 'error' : 'updated' ); if ( isset( $_COOKIE[ $key ] ) && ! empty( $_COOKIE[ $key ] ) ) { $messages = json_decode( stripcslashes( $_COOKIE[ $key ] ), true ); - $messages[] = $string; + $messages[] = $text; } else { - $messages = array( $string ); + $messages = array( $text ); } return gianism_set_cookie( $key, rawurlencode( json_encode( $messages ) ), time() + 180, '', false ); } diff --git a/app/Gianism/Helper/Monitor.php b/app/Gianism/Helper/Monitor.php index 9336c4b..f71e60d 100644 --- a/app/Gianism/Helper/Monitor.php +++ b/app/Gianism/Helper/Monitor.php @@ -23,6 +23,4 @@ class Monitor extends Singleton { protected function __construct( array $argument = array() ) { add_filter( 'cron_schedules', array( $this, 'cron_schedules' ) ); } - - } diff --git a/app/Gianism/Helper/Option.php b/app/Gianism/Helper/Option.php index 87af794..a0db80e 100644 --- a/app/Gianism/Helper/Option.php +++ b/app/Gianism/Helper/Option.php @@ -25,7 +25,8 @@ */ class Option extends Singleton { - use i18n, MessageHelper; + use i18n; + use MessageHelper; /** * Action name which fires on updating option @@ -88,11 +89,11 @@ protected function __construct( array $argument = [] ) { * Set default option * * @param string $key - * @param mixed $default + * @param mixed $default_value */ - public function set_default( $key, $default ) { + public function set_default( $key, $default_value ) { if ( ! isset( $this->values[ $key ] ) ) { - $this->values[ $key ] = $default; + $this->values[ $key ] = $default_value; } } @@ -360,7 +361,7 @@ public function is_network_activated() { if ( ! is_multisite() ) { return false; } - return in_array( gianism_root_dir() . '/wp-gianism.php', wp_get_active_network_plugins() ); + return in_array( gianism_root_dir() . '/wp-gianism.php', wp_get_active_network_plugins(), true ); } /** diff --git a/app/Gianism/Helper/ServiceManager.php b/app/Gianism/Helper/ServiceManager.php index f65707d..d0c2167 100644 --- a/app/Gianism/Helper/ServiceManager.php +++ b/app/Gianism/Helper/ServiceManager.php @@ -12,7 +12,8 @@ */ class ServiceManager extends Singleton { - use i18n, ExtensionManager; + use i18n; + use ExtensionManager; /** * @var array @@ -165,5 +166,4 @@ public function get_plugins() { } return $plugins; } - } diff --git a/app/Gianism/Helper/Session.php b/app/Gianism/Helper/Session.php index c396855..665fd2d 100644 --- a/app/Gianism/Helper/Session.php +++ b/app/Gianism/Helper/Session.php @@ -146,6 +146,4 @@ public function __get( $name ) { break; } } - - } diff --git a/app/Gianism/Pattern/AbstractController.php b/app/Gianism/Pattern/AbstractController.php index 16c6fc7..3accad6 100644 --- a/app/Gianism/Pattern/AbstractController.php +++ b/app/Gianism/Pattern/AbstractController.php @@ -10,5 +10,4 @@ abstract class AbstractController extends Singleton { use AppBase; - } diff --git a/app/Gianism/Pattern/AbstractNotice.php b/app/Gianism/Pattern/AbstractNotice.php index 78ffec9..6a7653c 100644 --- a/app/Gianism/Pattern/AbstractNotice.php +++ b/app/Gianism/Pattern/AbstractNotice.php @@ -192,5 +192,4 @@ public function __get( $name ) { break; } } - } diff --git a/app/Gianism/Pattern/AppBase.php b/app/Gianism/Pattern/AppBase.php index eb4cb24..4bb3e75 100644 --- a/app/Gianism/Pattern/AppBase.php +++ b/app/Gianism/Pattern/AppBase.php @@ -26,7 +26,8 @@ */ trait AppBase { - use i18n, MessageHelper; + use i18n; + use MessageHelper; protected $name = 'gianism'; @@ -50,9 +51,9 @@ public function __get( $name ) { global $wpdb; return $wpdb; case 'url': - return plugin_dir_url( dirname( dirname( dirname( __FILE__ ) ) ) ); + return plugin_dir_url( dirname( __DIR__, 2 ) ); case 'dir': - return plugin_dir_path( dirname( dirname( dirname( __FILE__ ) ) ) ); + return plugin_dir_path( dirname( __DIR__, 2 ) ); case 'option': return Option::get_instance(); case 'input': diff --git a/app/Gianism/Pattern/Application.php b/app/Gianism/Pattern/Application.php index ea78342..a0ada01 100644 --- a/app/Gianism/Pattern/Application.php +++ b/app/Gianism/Pattern/Application.php @@ -35,5 +35,4 @@ public function get_meta_owner( $key, $value ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared return (int) $wpdb->get_var( $wpdb->prepare( $sql, $key, $value ) ); } - } diff --git a/app/Gianism/Pattern/Singleton.php b/app/Gianism/Pattern/Singleton.php index 71b6486..40a0e83 100644 --- a/app/Gianism/Pattern/Singleton.php +++ b/app/Gianism/Pattern/Singleton.php @@ -42,5 +42,4 @@ final public static function get_instance( array $argument = [] ) { return self::$instances[ $class_name ]; } - } diff --git a/app/Gianism/Plugins/Analytics.php b/app/Gianism/Plugins/Analytics.php index 4cc19fd..247aa77 100644 --- a/app/Gianism/Plugins/Analytics.php +++ b/app/Gianism/Plugins/Analytics.php @@ -104,8 +104,8 @@ public function __construct( array $argument = [] ) { add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); add_filter( 'gianism_setting_screen_views', - function( $views, $slug ) { - if ( 'gianism' == $slug ) { + function ( $views, $slug ) { + if ( 'gianism' === $slug ) { $views['analytics'] = sprintf( ' %s', $this->_( 'Google Analytics' ) ); } return $views; @@ -328,7 +328,7 @@ public function table_create_url( $redirect ) { * @param $hook_suffix */ public function enqueue_scripts( $hook_suffix ) { - if ( 'settings_page_gianism' == $hook_suffix ) { + if ( 'settings_page_gianism' === $hook_suffix ) { // Script wp_enqueue_script( 'gianism-analytics-helper', $this->url . 'assets/js/admin-analytics-helper.js', [ 'jquery-form' ], $this->version, true ); wp_localize_script( @@ -355,7 +355,7 @@ public function ga_ajax() { } // Check data to retrieve $result = null; - switch ( $target = $this->input->get( 'target' ) ) { + switch ( $this->input->get( 'target' ) ) { case 'account': $properties = $this->ga ->management_webproperties @@ -376,7 +376,6 @@ public function ga_ajax() { break; default: throw new \Exception( $this->_( 'Invalid action.' ), 500 ); - break; } } catch ( \Exception $e ) { $json = array( @@ -385,7 +384,7 @@ public function ga_ajax() { 'message' => $e->getMessage(), ); } - echo json_encode( $json ); + wp_send_json( $json ); exit; } @@ -419,7 +418,7 @@ public function boot_auto_cron() { $this->crons = apply_filters( 'gianism_analytics_auto_loader_class', [], 'cron' ); // Parse directory $classes = $scan( $template_dir ); - if ( $template_dir != $stylesheet_dir ) { + if ( $template_dir !== $stylesheet_dir ) { $classes = array_merge( $classes, $scan( $stylesheet_dir ) ); } if ( ! empty( $classes ) ) { @@ -574,6 +573,4 @@ public function __get( $name ) { break; } } - - } diff --git a/app/Gianism/Plugins/AnalyticsFetcher.php b/app/Gianism/Plugins/AnalyticsFetcher.php index b8e146b..18faebe 100644 --- a/app/Gianism/Plugins/AnalyticsFetcher.php +++ b/app/Gianism/Plugins/AnalyticsFetcher.php @@ -28,7 +28,7 @@ class AnalyticsFetcher extends Singleton { * @return string */ protected function today() { - return date_i18n( 'Y-m-d', current_time( 'timestamp' ) ); + return date_i18n( 'Y-m-d' ); } /** @@ -55,11 +55,11 @@ protected function save( $date, $id, $value ) { /** * Fetch data from Google Analytics API * - * @param string $start_date Date string - * @param string $end_date Date string - * @param string $metrics CSV of metrics E.g., 'ga:visits,ga:pageviews' - * @param array $params Option params below - * @param bool $throw If set to true, throws exception + * @param string $start_date Date string + * @param string $end_date Date string + * @param string $metrics CSV of metrics E.g., 'ga:visits,ga:pageviews' + * @param array $params Option params below + * @param bool $throw_exception If set to true, throws exception * * @opt_param string dimensions A comma-separated list of Analytics dimensions. E.g., 'ga:browser,ga:city'. * @opt_param string filters A comma-separated list of dimension or metric filters to be applied to Analytics data. @@ -71,7 +71,7 @@ protected function save( $date, $id, $value ) { * @return array * @throws \Exception */ - public function fetch( $start_date, $end_date, $metrics, $params = [], $throw = false ) { + public function fetch( $start_date, $end_date, $metrics, $params = [], $throw_exception = false ) { try { if ( ! $this->ga || ! $this->view_id ) { throw new \Exception( 'Google Analytics is not connected.', 500 ); @@ -83,7 +83,7 @@ public function fetch( $start_date, $end_date, $metrics, $params = [], $throw = return []; } } catch ( \Exception $e ) { - if ( $throw ) { + if ( $throw_exception ) { throw $e; } else { error_log( sprintf( '[Gianism GA Error %s] %s', $e->getCode(), $e->getMessage() ) ); @@ -130,5 +130,4 @@ public function __get( $name ) { break; } } - } diff --git a/app/Gianism/Plugins/Bot.php b/app/Gianism/Plugins/Bot.php index f8e43e5..1c1fd48 100644 --- a/app/Gianism/Plugins/Bot.php +++ b/app/Gianism/Plugins/Bot.php @@ -114,7 +114,7 @@ public function register_post_type() { * @return string */ public function enter_title_here( $title, $post ) { - if ( $post->post_type == $this->post_type ) { + if ( $post->post_type === $this->post_type ) { $title = $this->_( 'Enter this bots name. Ex: Promotion Campaign 2014 mid' ); } @@ -128,7 +128,7 @@ public function enter_title_here( $title, $post ) { * @param \WP_Post $post */ public function save_post( $post_id, $post ) { - if ( wp_is_post_autosave( $post ) || wp_is_post_revision( $post ) || $this->post_type != $post->post_type ) { + if ( wp_is_post_autosave( $post ) || wp_is_post_revision( $post ) || $this->post_type !== $post->post_type ) { return; } if ( ! wp_verify_nonce( $this->input->post( '_gianismnonce' ), 'gianism_twitter_bot' ) ) { @@ -159,9 +159,9 @@ public function save_post( $post_id, $post ) { * @param string $suffix */ public function admin_enqueue_scripts( $suffix ) { - if ( false !== array_search( $suffix, array( 'post.php', 'post-new.php' ) ) ) { + if ( in_array( $suffix, array( 'post.php', 'post-new.php' ), true ) ) { $screen = get_current_screen(); - if ( $this->post_type == $screen->post_type ) { + if ( $this->post_type === $screen->post_type ) { wp_enqueue_script( 'gianism-twitter-bot-helper', $this->url . 'assets/js/admin-twitter-bot-helper.js', array( 'jquery-effects-highlight' ), $this->version, true ); wp_localize_script( 'gianism-twitter-bot-helper', @@ -181,7 +181,7 @@ public function admin_enqueue_scripts( $suffix ) { * @param \WP_Post $post */ public function edit_form_after_title( $post ) { - if ( $this->post_type == $post->post_type ) { + if ( $this->post_type === $post->post_type ) { wp_nonce_field( 'gianism_twitter_bot', '_gianismnonce', false ); include $this->dir . '/templates/edit/bot.php'; } @@ -204,7 +204,7 @@ public function get_schedule( $post ) { SQL; $results = $this->db->get_results( $this->db->prepare( $query, $post->ID, $this->time_key . '_%' ) ); $times = array(); - for ( $i = 1; $i <= 7; $i ++ ) { + for ( $i = 1; $i <= 7; $i++ ) { $times[ $this->time_key . '_' . $i ] = array(); } foreach ( $results as $result ) { @@ -297,7 +297,7 @@ public function register_cron() { function ( $matches ) { return $matches[1] . '0:00'; }, - date_i18n( 'Y-m-d H:i:00', current_time( 'timestamp' ) + 60 * 10 ) + date_i18n( 'Y-m-d H:i:00', time() + 60 * 10 ) ), 'U' ); @@ -335,7 +335,7 @@ public function execute_cron() { } $meta_key = $this->time_key . '_' . $date; // Get posts - $now = current_time( 'timestamp' ); + $now = time(); $before = $now - 60 * 9; $now = date_i18n( 'H:i:00', $now ); $before = date_i18n( 'H:i:00', $before ); @@ -388,7 +388,7 @@ public function get_columns( $columns ) { $new_columns = array(); foreach ( $columns as $key => $column ) { $new_columns[ $key ] = $column; - if ( 'date' == $key ) { + if ( 'date' === $key ) { $new_columns['end_date'] = $this->_( 'End Date' ); } } @@ -456,7 +456,7 @@ function ( $args, $content = '' ) use ( $gianism ) { ), $args ); - $left = strtotime( $args['limit'] ) - current_time( 'timestamp' ); + $left = strtotime( $args['limit'] ) - time(); if ( $left / ( 60 * 60 * 24 * 30 ) > 1 ) { return sprintf( $args['placeholder'], sprintf( $gianism->_( '%s months' ), floor( $left / ( 60 * 60 * 24 * 30 ) ) ) ); } elseif ( $left / ( 60 * 60 * 24 ) > 1 ) { diff --git a/app/Gianism/Plugins/PluginBase.php b/app/Gianism/Plugins/PluginBase.php index e61ce94..7d5c221 100644 --- a/app/Gianism/Plugins/PluginBase.php +++ b/app/Gianism/Plugins/PluginBase.php @@ -49,6 +49,4 @@ public function __get( $name ) { break; } } - - } diff --git a/app/Gianism/Service/AbstractService.php b/app/Gianism/Service/AbstractService.php index ae83b9c..7fcdb58 100644 --- a/app/Gianism/Service/AbstractService.php +++ b/app/Gianism/Service/AbstractService.php @@ -193,16 +193,17 @@ public function parse_request( $action, \WP_Query &$wp_query ) { $wp_query->set_404(); return; } - if ( 'default' != $action && ! $this->input->verify_nonce( $this->input->nonce_action( "{$this->service_name}_{$action}" ) ) ) { + if ( 'default' !== $action && ! $this->input->verify_nonce( $this->input->nonce_action( "{$this->service_name}_{$action}" ) ) ) { // If not default, nonce required. $this->input->wp_die( __( 'This request seems to be a wrong access. Please try again.', 'wp-gianism' ), 403 ); } - if ( 'default' != $action && method_exists( get_called_class(), $method ) ) { + if ( 'default' !== $action && method_exists( get_called_class(), $method ) ) { // Method found, just call $this->{$method}( $wp_query ); } else { // Else, call default. - if ( $specified_action = $this->session->get( 'action' ) ) { + $specified_action = $this->session->get( 'action' ); + if ( $specified_action ) { // If session is set, override with it. $action = $specified_action; } @@ -234,6 +235,7 @@ protected function handle_connect( \WP_Query $wp_query ) { } // Is user connected already? if ( $this->is_connected( get_current_user_id() ) ) { + // translators: %s is service name. throw new \Exception( sprintf( __( 'You are already connected with %s', 'wp-gianism' ), $this->verbose_service_name ) ); } // Set redirect URL @@ -274,10 +276,12 @@ protected function handle_disconnect( \WP_Query $wp_query ) { } // Has connection? if ( ! $this->is_connected( get_current_user_id() ) ) { + // translators: %s is service name. throw new \Exception( sprintf( __( 'Your account is not connected with %s', 'wp-gianism' ), $this->verbose_service_name ) ); } // O.K. $this->disconnect( get_current_user_id() ); + // translators: %s is service name. $this->add_message( sprintf( __( 'Your account is now unlinked from %s.', 'wp-gianism' ), $this->verbose_service_name ) ); // Redirect wp_redirect( $this->filter_redirect( $redirect_url, 'disconnect' ) ); @@ -308,7 +312,8 @@ public function handle_login( \WP_Query $wp_query ) { 'redirect_to' => $this->input->get( 'redirect_to' ), 'action' => 'login', ]; - if ( ( $blog_id = $this->input->get( 'blog_id' ) ) ) { + $blog_id = $this->input->get( 'blog_id' ); + if ( $blog_id ) { // Store blog id if blog id is specified. $session['blog_id'] = (int) $blog_id; } @@ -377,9 +382,11 @@ public function profile_connect( \WP_User $user ) { public function connection_message( $context = 'connected' ) { switch ( $context ) { case 'connected': + // translators: %s is service name. return sprintf( __( 'Your account is already connected with %s account.', 'wp-gianism' ), $this->verbose_service_name ); break; default: // Disconnected + // translators: %1$s is service name, %2$s is site name. return sprintf( __( 'Connecting with %1$s, you can login with %2$s via %1$s without password or email address.', 'wp-gianism' ), $this->verbose_service_name, get_bloginfo( 'name' ) ); break; } @@ -401,32 +408,21 @@ public function login_form( $is_register = false, $redirect_to = '', $context = /** * Returns redirect to url if set. * - * @param string $default + * @param string $default_url * @param array $args * * @return string */ - protected function get_redirect_to( $default, $args = array() ) { + protected function get_redirect_to( $default_url, $args = array() ) { + $redirect_to = $default_url; if ( isset( $_REQUEST['redirect_to'] ) ) { $domain = $_SERVER['SERVER_NAME']; if ( preg_match( "/^(https?:\/\/{$domain}|\/)/", $_REQUEST['redirect_to'] ) ) { $redirect_to = $_REQUEST['redirect_to']; if ( ! empty( $args ) ) { - $redirect_to .= ( false !== strpos( $redirect_to, '?' ) ) ? '&' : '?'; - $counter = 0; - foreach ( $args as $key => $val ) { - if ( 0 == $counter ) { - $redirect_to .= '&'; - } - $redirect_to .= $key . '=' . rawurlencode( $val ); - $counter ++; - } + $redirect_to = add_query_arg( $args, $redirect_to ); } - } else { - $redirect_to = $default; } - } else { - $redirect_to = $default; } return $this->filter_redirect( $redirect_to, 'default' ); } @@ -566,9 +562,12 @@ public function button( $text, $href, $icon_name = true, array $class_names = [ $icon = ''; } // If SVG exists, use it for public button style. - if ( in_array( 'wpg-guideline-button', $class_names ) && ( $file = $this->svg_path() ) ) { - $icon = $this->url . '/assets/img/brands/' . $file; - $icon = sprintf( '', esc_url( $icon ) ); + if ( in_array( 'wpg-guideline-button', $class_names, true ) ) { + $file = $this->svg_path(); + if ( $file ) { + $icon = $this->url . '/assets/img/brands/' . $file; + $icon = sprintf( '', esc_url( $icon ) ); + } } $class_attr = implode( ' ', @@ -620,6 +619,7 @@ function ( $attr ) { * @return string */ protected function login_label( $register = false, $context = '' ) { + // translators: %s is service name. return sprintf( __( 'Log in with %s', 'wp-gianism' ), $this->verbose_service_name ); } @@ -710,6 +710,7 @@ public function connect_button( $redirect_to = '' ) { $args = array( 'gianism-ga-category' => "gianism/{$this->service_name}", 'gianism-ga-action' => 'connect', + // translators: %s is service name. 'gianism-ga-label' => sprintf( __( 'Connect %s', 'wp-gianism' ), $this->verbose_service_name ), ); @@ -737,7 +738,9 @@ public function disconnect_button( $redirect_to = '' ) { $args = array( 'gianism-ga-category' => "gianism/{$this->service_name}", 'gianism-ga-action' => 'disconnect', + // translators: %s is service name. 'gianism-ga-label' => sprintf( __( 'Disconnect %s', 'wp-gianism' ), $this->verbose_service_name ), + // translators: %s is service name. 'gianism-confirm' => sprintf( __( 'You really disconnect from %s? If so, please be sure about your credential(email, password), or else you might not be able to login again.', 'wp-gianism' ), $this->verbose_service_name ), ); @@ -847,6 +850,7 @@ protected function valid_username_from_mail( $email ) { * @return string */ protected function api_error_string() { + // translators: %s is service name. return sprintf( __( '%s API returns error.', 'wp-gianism' ), $this->verbose_service_name ); } @@ -856,6 +860,7 @@ protected function api_error_string() { * @return string */ protected function duplicate_account_string() { + // translators: %s is service name. return sprintf( __( 'This %s account is already connected with others.', 'wp-gianism' ), $this->verbose_service_name ); } @@ -865,6 +870,7 @@ protected function duplicate_account_string() { * @param string $who */ protected function welcome( $who ) { + // translators: %s is user name. $this->add_message( sprintf( __( 'Welcome, %s!', 'wp-gianism' ), $who ) ); } @@ -911,6 +917,7 @@ protected function kill_wrong_access() { */ protected function test_user_can_register() { if ( ! $this->user_can_register() ) { + // translators: %s is service name. throw new \Exception( sprintf( __( 'Registration via %s is not allowed.', 'wp-gianism' ), $this->verbose_service_name ) ); } @@ -960,6 +967,7 @@ protected function get_response( $endpoint, $request = '', $method = 'POST', $js case 'PUT': case 'PATCH': curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $method ); + // Other, same as POST. case 'POST': curl_setopt( $ch, CURLOPT_POST, true ); if ( is_array( $request ) ) { @@ -971,6 +979,7 @@ protected function get_response( $endpoint, $request = '', $method = 'POST', $js break; case 'DELETE': curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'DELETE' ); + // Other, same as GET. case 'GET': $args = array(); if ( is_array( $request ) ) { @@ -982,7 +991,6 @@ protected function get_response( $endpoint, $request = '', $method = 'POST', $js break; default: return array(); - break; } curl_setopt( $ch, CURLOPT_URL, $endpoint ); if ( ! empty( $additional_headers ) ) { @@ -992,7 +1000,6 @@ protected function get_response( $endpoint, $request = '', $method = 'POST', $js curl_close( $ch ); return json_decode( $response ); - } /** @@ -1037,6 +1044,7 @@ public function confirmation_message( $context = 'login' ) { */ public function target_credentials( $context = 'login' ) { return [ + // translators: %s is serfice name. 'id' => sprintf( __( '%s User ID', 'wp-gianism' ), $this->verbose_service_name ), 'profile' => __( 'Profile', 'wp-gianism' ), 'email' => __( 'Email', 'wp-gianism' ), @@ -1065,13 +1073,10 @@ public function __get( $name ) { $segments = explode( '\\', get_called_class() ); return strtolower( $segments[ count( $segments ) - 1 ] ); - break; case 'enabled': return $this->option->is_enabled( $this->service_name ); - break; default: return parent::__get( $name ); - break; } } } diff --git a/app/Gianism/Service/Facebook.php b/app/Gianism/Service/Facebook.php index b315a3b..0196d8f 100644 --- a/app/Gianism/Service/Facebook.php +++ b/app/Gianism/Service/Facebook.php @@ -14,7 +14,7 @@ * @author Takahashi Fumiki * @property-read \Facebook\Facebook|\WP_Error $api Facebook object * @property-read \Facebook\Facebook|\WP_Error $admin Facebook object for Admin Use - * @property-read int $admin_id + * @property-read int|string $admin_id * @property-read array|false $admin_account * @property-read array $admin_pages */ @@ -131,8 +131,8 @@ protected function init_action() { // Add view for API add_filter( 'gianism_setting_screen_views', - function( $views, $slug ) { - if ( 'gianism' == $slug ) { + function ( $views, $slug ) { + if ( 'gianism' === $slug ) { $views['fb-api'] = sprintf( ' %s', $this->_( 'Facebook API' ) ); } return $views; @@ -224,8 +224,8 @@ public function handle_admin( \WP_Query $wp_query ) { if ( $this->input->request( 'publish' ) ) { add_filter( 'gianism_facebook_permissions', - function( $permission, $action ) { - if ( 'admin' == $action ) { + function ( $permission, $action ) { + if ( 'admin' === $action ) { $permission[] = 'publish_actions'; } return $permission; @@ -267,8 +267,9 @@ protected function handle_default( $action ) { } // Get user ID $user = $this->get_returned_user(); - // If user doesn't exists, try to register. - if ( ! ( $user_id = $this->get_meta_owner( $this->umeta_id, $user['id'] ) ) ) { + // If user doesn't exist, try to register. + $user_id = $this->get_meta_owner( $this->umeta_id, $user['id'] ) + if ( ! $user_id ) { // Test $this->test_user_can_register(); // Check email @@ -346,9 +347,10 @@ protected function handle_default( $action ) { if ( ! isset( $user['email'] ) || ! is_email( $user['email'] ) ) { throw new \Exception( $this->mail_fail_string() ); } - $email = $user['email']; + $email = $user['email']; + $email_owner = $this->mail_owner( $email ); // Check if other user has these as meta_value - if ( ( $email_owner = $this->mail_owner( $email ) ) && get_current_user_id() != $email_owner ) { + if ( $email_owner && get_current_user_id() !== $email_owner ) { throw new \Exception( $this->duplicate_account_string() ); } // Now let's save user_data @@ -397,6 +399,7 @@ protected function handle_default( $action ) { $long_token = $oauth->getLongLivedAccessToken( $token ); // O.K. Token ready and save it. update_option( 'gianism_facebook_admin_token', $long_token ); + // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested update_option( 'gianism_facebook_admin_refreshed', current_time( 'timestamp' ) ); $this->add_message( $this->_( 'Access token is saved.' ) ); } catch ( \Exception $e ) { @@ -425,7 +428,6 @@ protected function handle_default( $action ) { $this->input->wp_die( sprintf( $this->_( 'Sorry, but wrong access. Please go back to %s.' ), home_url( '/' ), get_bloginfo( 'name' ) ), 500, false ); break; } - } /** @@ -473,7 +475,7 @@ public function get_admin_connect_link( $require_publish = false ) { * Update admin account id. */ public function update_facebook_admin() { - if ( 'gianism' == $this->input->get( 'page' ) && wp_verify_nonce( $this->input->post( '_wpnonce' ), 'gianism_fb_account' ) ) { + if ( 'gianism' === $this->input->get( 'page' ) && wp_verify_nonce( $this->input->post( '_wpnonce' ), 'gianism_fb_account' ) ) { update_option( 'gianism_facebook_admin_id', $this->input->post( 'fb_account_id' ) ); $this->add_message( $this->_( 'Saved facebook account to use.' ) ); wp_redirect( admin_url( 'options-general.php?page=gianism&view=fb-api' ) ); @@ -489,7 +491,8 @@ public function update_facebook_admin() { */ public function get_returned_user() { $redirect_helper = $this->api->getRedirectLoginHelper(); - if ( ! ( $access_token = $redirect_helper->getAccessToken( $this->get_redirect_endpoint() ) ) ) { + $access_token = $redirect_helper->getAccessToken( $this->get_redirect_endpoint() ); + if ( ! $access_token ) { throw new \Exception( $redirect_helper->getError(), $redirect_helper->getErrorCode() ); } $user = $this->get_user_profile( 'login', $access_token ); @@ -507,7 +510,8 @@ public function get_returned_user() { * @return int */ public function mail_owner( $email ) { - if ( $owner = email_exists( $email ) ) { + $owner = email_exists( $email ); + if ( $owner ) { return $owner; } return $this->get_meta_owner( $this->umeta_mail, $email ); @@ -652,7 +656,8 @@ public function __get( $name ) { break; case 'admin': if ( is_null( $this->_admin_api ) ) { - if ( ! $this->fb_use_api || ! ( $token = $this->option->get( 'gianism_facebook_admin_token', false ) ) ) { + $token = $this->option->get( 'gianism_facebook_admin_token', false ); + if ( ! $this->fb_use_api || ! $token ) { return new \WP_Error( 404, $this->_( 'Token is not set. Please get it.' ) ); } try { @@ -666,6 +671,7 @@ public function __get( $name ) { ); // Check last updated $updated = $this->option->get( 'gianism_facebook_admin_refreshed', 0 ); + // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested if ( ! $updated || current_time( 'timestamp' ) > $updated + ( 60 * 60 * 24 * 60 ) ) { return new \WP_Error( 410, $this->_( 'Token is outdated. Please update it.' ) ); } @@ -742,12 +748,12 @@ public function get_graph_version() { */ public function get_current_page_api() { $page_id = $this->admin_id; - if ( 'me' == $page_id ) { + if ( 'me' === $page_id ) { return new \WP_Error( 500, __( 'Page is not set.', 'wp-gianism' ) ); } $token = ''; foreach ( $this->admin_pages as $page ) { - if ( $page_id == $page['id'] ) { + if ( $page_id === $page['id'] ) { $token = $page['token']; break; } @@ -826,5 +832,4 @@ public function fan_gate_helper() { // Do nothing _deprecated_function( __METHOD__, 'Gianism 3.0.0', null ); } - } diff --git a/app/Gianism/Service/Google.php b/app/Gianism/Service/Google.php index a132ef8..1a904fd 100644 --- a/app/Gianism/Service/Google.php +++ b/app/Gianism/Service/Google.php @@ -102,8 +102,8 @@ protected function __construct( array $argument = [] ) { // Filter rewrite name add_filter( 'gianism_filter_service_prefix', - function( $prefix ) { - if ( 'google-auth' == $prefix ) { + function ( $prefix ) { + if ( 'google-auth' === $prefix ) { $prefix = 'google'; } return $prefix; @@ -203,7 +203,7 @@ protected function handle_default( $action ) { // Check if other user has these as meta_value $email = $profile['email']; $email_owner = $this->get_meta_owner( $this->umeta_account, $email ); - if ( $email_owner && ( get_current_user_id() != $email_owner ) ) { + if ( $email_owner && ( get_current_user_id() !== $email_owner ) ) { throw new \Exception( $this->duplicate_account_string() ); } // Now let's save user data @@ -310,6 +310,7 @@ protected function get_api_url( $action ) { } protected function login_label( $register = false, $context = '' ) { + // translators: %s is service name. return sprintf( _x( 'Sign in with %s', 'login label', 'wp-gianism' ), $this->verbose_service_name ); } diff --git a/app/Gianism/Service/Line.php b/app/Gianism/Service/Line.php index 502685d..4a043f8 100644 --- a/app/Gianism/Service/Line.php +++ b/app/Gianism/Service/Line.php @@ -45,8 +45,8 @@ protected function __construct( array $argument = [] ) { // Filter rewrite name add_filter( 'gianism_filter_service_prefix', - function( $prefix ) { - if ( 'line-auth' == $prefix ) { + function ( $prefix ) { + if ( 'line-auth' === $prefix ) { $prefix = 'line'; } return $prefix; @@ -81,7 +81,8 @@ protected function get_api_url( $action ) { 'state' => $state, // 'prompt' => 'consent', // For Debug by displaying consent screen always. ]; - if ( ( $prompt = $this->line_add_friend_prompt ) ) { + $prompt = $this->line_add_friend_prompt; + if ( $prompt ) { $params['bot_prompt'] = $prompt; } /** @@ -290,7 +291,8 @@ public function handle_default( $action ) { 'redirect_to' => $redirect_url, ] ); - $this->input->wp_die( sprintf( __( 'Sorry, but wrong access. Please go back to %2$s.', 'wp-gianism' ), home_url( '/' ), get_bloginfo( 'name' ) ), 500, false ); + // translators: %1$s is URL, %2$s is a site name. + $this->input->wp_die( sprintf( __( 'Sorry, but wrong access. Please go back to %2$s.', 'wp-gianism' ), esc_url( home_url( '/' ) ), get_bloginfo( 'name' ) ), 500, false ); break; } } diff --git a/app/Gianism/Service/NoMailService.php b/app/Gianism/Service/NoMailService.php index 5a49ef7..1681318 100644 --- a/app/Gianism/Service/NoMailService.php +++ b/app/Gianism/Service/NoMailService.php @@ -67,7 +67,7 @@ protected function wp_mail( $user_id, $subject, $message, $headers = '', $attach } /** - * Override default wp_mai + * Override default wp_mail * * @param array $args * @@ -76,7 +76,8 @@ protected function wp_mail( $user_id, $subject, $message, $headers = '', $attach final public function mail_handler( $args ) { $tos = []; foreach ( is_array( $args['to'] ) ? $args['to'] : [ $args['to'] ] as $to ) { - if ( $this->is_pseudo_mail( $to ) && ( $user_id = email_exists( $to ) ) ) { + $user_id = email_exists( $to ); + if ( $this->is_pseudo_mail( $to ) && $user_id ) { // Send mail $this->wp_mail( $user_id, $args['subject'], $args['message'], $args['headers'], $args['attachments'] ); } else { diff --git a/app/Gianism/Service/Twitter.php b/app/Gianism/Service/Twitter.php index 04b0c1a..2000098 100644 --- a/app/Gianism/Service/Twitter.php +++ b/app/Gianism/Service/Twitter.php @@ -118,7 +118,7 @@ protected function __construct( array $argument = array() ) { if ( version_compare( phpversion(), '5.5.0', '<' ) && $this->enabled ) { add_action( 'admin_notices', - function() { + function () { printf( '

%s

', sprintf( $this->_( 'Twitter Login requires PHP5.5 and over but yours is %s. Every twitter login will be failed.' ), phpversion() ) @@ -261,7 +261,7 @@ protected function handle_default( $action ) { $screen_name = $access_token['screen_name']; // Check if other user has registered $id_owner = $this->get_meta_owner( $this->umeta_id, $twitter_id ); - if ( $id_owner && ( get_current_user_id() != $id_owner ) ) { + if ( $id_owner && ( get_current_user_id() !== $id_owner ) ) { throw new \Exception( $this->duplicate_account_string() ); } // O.K. @@ -427,7 +427,8 @@ public function get_oauth( $oauth_token = null, $oauth_token_secret = null ) { * Tweet with Owner ID * * @see https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets - * @param string $string + * + * @param string $text * @param null $deprecated Since 5.1.0 * @param array $options * @param string $token @@ -435,12 +436,12 @@ public function get_oauth( $oauth_token = null, $oauth_token_secret = null ) { * * @return object|\WP_Error Json format object. */ - public function tweet( $string, $deprecated = null, array $options = [], $token = '', $secret = '' ) { + public function tweet( $text, $deprecated = null, array $options = [], $token = '', $secret = '' ) { return $this->call_api( 'tweets', array_merge( [ - 'text' => $string, + 'text' => $text, ], $options ), @@ -454,14 +455,15 @@ public function tweet( $string, $deprecated = null, array $options = [], $token /** * Tweet with media * - * @param string $string + * @param string $text * @param array $medias * @param TwitterOAuth $oauth * @param string $token * @param string $secret + * * @return object|\WP_Error JSON format object */ - public function tweet_with_media( $string, array $medias, $oauth = null, $token = '', $secret = '' ) { + public function tweet_with_media( $text, array $medias, $oauth = null, $token = '', $secret = '' ) { $media_ids = []; foreach ( $medias as $media ) { $media_id = $this->upload( $media, $oauth ); @@ -473,7 +475,7 @@ public function tweet_with_media( $string, array $medias, $oauth = null, $token return new \WP_Error( 500, __( 'Failed to upload media', 'wp-gianism' ) ); } return $this->tweet( - $string, + $text, $oauth, [ 'media' => [ @@ -511,7 +513,7 @@ public function upload( $path_or_id, $oauth = null ) { return new \WP_Error( 404, __( 'File not found.', 'wp-gianism' ) ); } $path = sys_get_temp_dir() . '/' . tmpfile() . '-' . basename( $path_or_id ); - if ( ! @file_put_contents( $path, $file ) ) { + if ( ! file_put_contents( $path, $file ) ) { return new \WP_Error( 500, __( 'Failed to download media', 'wp-gianism' ) ); } $object = $path; diff --git a/app/Gianism/UI/Screen.php b/app/Gianism/UI/Screen.php index d9c4ae7..de7df57 100644 --- a/app/Gianism/UI/Screen.php +++ b/app/Gianism/UI/Screen.php @@ -93,7 +93,7 @@ public function switch_button( $name, $current_value, $value = 1 ) { ?>
> + value="">