Skip to content

Commit

Permalink
Merge pull request #135 from fumikito/feature/php82andwp6.2
Browse files Browse the repository at this point in the history
Feature/php82andwp6.2
  • Loading branch information
fumikito authored Aug 28, 2024
2 parents be8a500 + baba30b commit 52b52c1
Show file tree
Hide file tree
Showing 64 changed files with 475 additions and 339 deletions.
1 change: 1 addition & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ node_modules
package.json
package-lock.json
phpdoc.xml
phpstan.neon
phpunit.xml.dist
phpcs.ruleset.xml
composer.lock
Expand Down
45 changes: 41 additions & 4 deletions .github/workflows/wordpress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,49 @@ jobs:
- name: Install WordPress
run: bash bin/install-wp-tests.sh wordpress root root 127.0.0.1:3306 ${{ matrix.wp }}

#- name: Check PHP syntax
# run: composer lint

- name: Run Unit test
run: composer test

lint:
name: PHP Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- name: Setup PHP with composer v2
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Check PHP syntax
run: composer lint

analyze:
name: Check PHP code quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- name: Setup PHP with composer v2
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run PHP Stan
run: composer analyze:github

assets:
name: Assets Test
runs-on: ubuntu-latest
Expand All @@ -77,7 +114,7 @@ jobs:

status-check:
name: Status Check
needs: [ test, assets ]
needs: [ test, assets, lint, analyze ]
runs-on: ubuntu-latest
steps:
- name: Display Status
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

Contributors: Takahashi_Fumiki, hametuha
Tags: facebook,twitter,google,account,oauth,community,social,sns
Tested up to: 6.2
Stable Tag: 5.0.0
Requires at least: 5.6
Tested up to: 6.6
Stable Tag: 5.2.0
Requires at least: 5.9
Requires PHP: 7.2
License: GPL 2.0 or later
License: GPL2 or Later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Connect user accounts with significant web services like Facebook, Twitter, etc. Stand on the shoulders of giants!
Expand Down Expand Up @@ -96,4 +96,4 @@ Here is a list of change logs.

----

Please refer [changelog.md](https://github.com/fumikito/Gianism/blob/master/changelog.md) for older change logs,
Please refer [changelog.md](https://github.com/fumikito/Gianism/blob/master/changelog.md) for older change logs,
8 changes: 4 additions & 4 deletions app/Gianism/Api/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Gianism\Api;

use Gianism\Pattern\Singleton;
use Gianism\Plugins\AnalyticsFetcher;

/**
Expand Down Expand Up @@ -40,6 +39,7 @@ abstract protected function get_result();
* @param array $argument
*/
protected function __construct( array $argument = array() ) {
parent::__construct( $argument );
add_action( 'wp_ajax_' . static::ACTION, array( $this, 'ajax' ) );
if ( ! static::ONLY_MEMBER ) {
add_action( 'wp_ajax_nopriv_' . static::ACTION, array( $this, 'ajax' ) );
Expand All @@ -65,12 +65,12 @@ protected function parse_result( array $result ) {
*/
public function ajax() {
try {
if ( static::NONCE_ACTION && ! wp_verify_nonce( $this->get( '_wpnonce' ), static::NONCE_ACTION ) ) {
throw new \Exception( $this->_( 'You have no permission.' ), 403 );
if ( static::NONCE_ACTION && ! wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), static::NONCE_ACTION ) ) {
throw new \Exception( __( 'You have no permission.', 'wp-gianism' ), 403 );
}
$result = $this->get_result();
if ( ! is_array( $result ) ) {
throw new \Exception( $this->_( 'Wrong value is returned.' ), 500 );
throw new \Exception( __( 'Wrong value is returned.', 'wp-gianism' ), 500 );
}
$result = $this->parse_result( $result );
nocache_headers();
Expand Down
2 changes: 1 addition & 1 deletion app/Gianism/Api/Ga.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
}
}

Expand Down
3 changes: 2 additions & 1 deletion app/Gianism/Api/ShortCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Gianism\Api;

use \Gianism\Pattern\Application;
use Gianism\Pattern\Application;

/**
* Short code API
Expand All @@ -17,6 +17,7 @@ class ShortCodes extends Application {
* @param array $argument
*/
public function __construct( array $argument = [] ) {
parent::__construct( $argument );
add_shortcode( 'gianism_login', [ $this, 'login_short_code' ] );
add_shortcode( 'gianism_connection', [ $this, 'profile_connection_short_code' ] );
}
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static function init() {
* @param array $argument
*/
protected function __construct( array $argument = [] ) {
parent::__construct( $argument );
// Register assets
add_action( 'init', array( $this, 'register_assets' ) );
// Admin page
Expand Down
1 change: 0 additions & 1 deletion app/Gianism/Commands/CommandSkeleton.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
class CommandSkeleton extends \WP_CLI_Command {

use AppBase;

}
4 changes: 4 additions & 0 deletions app/Gianism/Commands/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}

Expand Down Expand Up @@ -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 ) ) );
}

Expand All @@ -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' ] );
Expand Down Expand Up @@ -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 );
Expand Down
5 changes: 3 additions & 2 deletions app/Gianism/Controller/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Admin extends AbstractController {
* @param array $argument
*/
protected function __construct( array $argument = [] ) {
parent::__construct( $argument );
if ( $this->option->is_network_activated() && ! is_main_site() ) {
return;
}
Expand Down Expand Up @@ -108,7 +109,7 @@ public function invalid_option_notices() {
return;
}
array_unshift( $this->invalid_options, '<strong>[Gianism]</strong>' );
printf( '<div class="error"><p>%s</p></div>', implode( '<br />', $this->invalid_options ) );
printf( '<div class="error"><p>%s</p></div>', wp_kses_post( implode( '<br />', $this->invalid_options ) ) );
}

/**
Expand Down Expand Up @@ -148,7 +149,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(
Expand Down
11 changes: 7 additions & 4 deletions app/Gianism/Controller/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Login extends AbstractController {
* @param array $argument
*/
protected function __construct( array $argument = [] ) {
parent::__construct( $argument );

if ( $this->option->is_enabled() ) {
// Only for account holder
Expand Down Expand Up @@ -86,14 +87,17 @@ public function login_form( $before = '', $after = '', $register = false, $redir
$class_name[] = 'public-style';
break;
}
$class_name = empty( $class_name ) ? '' : sprintf( ' class="%s"', implode( ' ', $class_name ) );
$class_name = $class_name ? '' : sprintf( ' class="%s"', esc_attr( implode( ' ', $class_name ) ) );
$before = sprintf( '<div id="wpg-login"%s>', $class_name );
}
if ( empty( $after ) ) {
$after = '</div>';
}
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;
/**
Expand Down Expand Up @@ -151,5 +155,4 @@ public function woo_form() {
}
$this->login_form( '', '', false, $redirect, 'woo-account' );
}

}
1 change: 1 addition & 0 deletions app/Gianism/Controller/Network.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Network extends AbstractController {
* @param array $argument
*/
protected function __construct( array $argument = [] ) {
parent::__construct( $argument );
// Add network notice
add_action( 'admin_notices', [ $this, 'network_notice' ] );
// Set role.
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Controller/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Profile extends AbstractController {
* @param array $argument
*/
protected function __construct( array $argument = [] ) {
parent::__construct( $argument );
// If not enabled, skip.
if ( ! $this->option->is_enabled() ) {
return;
Expand Down
19 changes: 12 additions & 7 deletions app/Gianism/Controller/ProfileChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
class ProfileChecker extends AbstractController {

public function __construct( array $argument = [] ) {
parent::__construct( $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() ) {
Expand Down Expand Up @@ -69,8 +70,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;
}
Expand Down Expand Up @@ -122,10 +126,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(),
Expand Down Expand Up @@ -192,6 +196,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 <a href="%s">here</a>.', 'wp-gianism' ), $this->redirect_url() );
$message = apply_filters( 'gianism_profile_error_popup', $message, $this->redirect_url(), $error );
$this->add_message( $message, true );
Expand All @@ -211,7 +216,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 )
Expand Down
Loading

0 comments on commit 52b52c1

Please sign in to comment.