@@ -4,29 +4,29 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface MultilingualContract |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @param int|string $postId |
|
| 9 | - * @return int |
|
| 10 | - */ |
|
| 11 | - public function getPostId($postId); |
|
| 7 | + /** |
|
| 8 | + * @param int|string $postId |
|
| 9 | + * @return int |
|
| 10 | + */ |
|
| 11 | + public function getPostId($postId); |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @return array |
|
| 15 | - */ |
|
| 16 | - public function getPostIds(array $postIds); |
|
| 13 | + /** |
|
| 14 | + * @return array |
|
| 15 | + */ |
|
| 16 | + public function getPostIds(array $postIds); |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @return bool |
|
| 20 | - */ |
|
| 21 | - public function isActive(); |
|
| 18 | + /** |
|
| 19 | + * @return bool |
|
| 20 | + */ |
|
| 21 | + public function isActive(); |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @return bool |
|
| 25 | - */ |
|
| 26 | - public function isEnabled(); |
|
| 23 | + /** |
|
| 24 | + * @return bool |
|
| 25 | + */ |
|
| 26 | + public function isEnabled(); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @return bool |
|
| 30 | - */ |
|
| 31 | - public function isSupported(); |
|
| 28 | + /** |
|
| 29 | + * @return bool |
|
| 30 | + */ |
|
| 31 | + public function isSupported(); |
|
| 32 | 32 | } |
@@ -8,12 +8,12 @@ |
||
| 8 | 8 | * @param int|string $postId |
| 9 | 9 | * @return int |
| 10 | 10 | */ |
| 11 | - public function getPostId($postId); |
|
| 11 | + public function getPostId( $postId ); |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * @return array |
| 15 | 15 | */ |
| 16 | - public function getPostIds(array $postIds); |
|
| 16 | + public function getPostIds( array $postIds ); |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * @return bool |
@@ -20,17 +20,17 @@ |
||
| 20 | 20 | defined('WPINC') || die; |
| 21 | 21 | |
| 22 | 22 | if (!class_exists('GL_Plugin_Check_v4')) { |
| 23 | - require_once __DIR__.'/activate.php'; |
|
| 23 | + require_once __DIR__.'/activate.php'; |
|
| 24 | 24 | } |
| 25 | 25 | if ((new GL_Plugin_Check_v4(__FILE__))->canProceed()) { |
| 26 | - require_once __DIR__.'/autoload.php'; |
|
| 27 | - require_once __DIR__.'/compatibility.php'; |
|
| 28 | - require_once __DIR__.'/deprecated.php'; |
|
| 29 | - require_once __DIR__.'/helpers.php'; |
|
| 30 | - $app = new GeminiLabs\SiteReviews\Application(); |
|
| 31 | - $app->make('Provider')->register($app); |
|
| 32 | - register_activation_hook(__FILE__, array($app, 'activate')); |
|
| 33 | - register_deactivation_hook(__FILE__, array($app, 'deactivate')); |
|
| 34 | - register_shutdown_function(array($app, 'catchFatalError')); |
|
| 35 | - $app->init(); |
|
| 26 | + require_once __DIR__.'/autoload.php'; |
|
| 27 | + require_once __DIR__.'/compatibility.php'; |
|
| 28 | + require_once __DIR__.'/deprecated.php'; |
|
| 29 | + require_once __DIR__.'/helpers.php'; |
|
| 30 | + $app = new GeminiLabs\SiteReviews\Application(); |
|
| 31 | + $app->make('Provider')->register($app); |
|
| 32 | + register_activation_hook(__FILE__, array($app, 'activate')); |
|
| 33 | + register_deactivation_hook(__FILE__, array($app, 'deactivate')); |
|
| 34 | + register_shutdown_function(array($app, 'catchFatalError')); |
|
| 35 | + $app->init(); |
|
| 36 | 36 | } |
@@ -17,20 +17,20 @@ |
||
| 17 | 17 | * Text Domain: site-reviews |
| 18 | 18 | * Domain Path: languages |
| 19 | 19 | */ |
| 20 | -defined('WPINC') || die; |
|
| 20 | +defined( 'WPINC' ) || die; |
|
| 21 | 21 | |
| 22 | -if (!class_exists('GL_Plugin_Check_v4')) { |
|
| 22 | +if( !class_exists( 'GL_Plugin_Check_v4' ) ) { |
|
| 23 | 23 | require_once __DIR__.'/activate.php'; |
| 24 | 24 | } |
| 25 | -if ((new GL_Plugin_Check_v4(__FILE__))->canProceed()) { |
|
| 25 | +if( (new GL_Plugin_Check_v4( __FILE__ ))->canProceed() ) { |
|
| 26 | 26 | require_once __DIR__.'/autoload.php'; |
| 27 | 27 | require_once __DIR__.'/compatibility.php'; |
| 28 | 28 | require_once __DIR__.'/deprecated.php'; |
| 29 | 29 | require_once __DIR__.'/helpers.php'; |
| 30 | 30 | $app = new GeminiLabs\SiteReviews\Application(); |
| 31 | - $app->make('Provider')->register($app); |
|
| 32 | - register_activation_hook(__FILE__, array($app, 'activate')); |
|
| 33 | - register_deactivation_hook(__FILE__, array($app, 'deactivate')); |
|
| 34 | - register_shutdown_function(array($app, 'catchFatalError')); |
|
| 31 | + $app->make( 'Provider' )->register( $app ); |
|
| 32 | + register_activation_hook( __FILE__, array( $app, 'activate' ) ); |
|
| 33 | + register_deactivation_hook( __FILE__, array( $app, 'deactivate' ) ); |
|
| 34 | + register_shutdown_function( array( $app, 'catchFatalError' ) ); |
|
| 35 | 35 | $app->init(); |
| 36 | 36 | } |
@@ -125,7 +125,8 @@ |
||
| 125 | 125 | sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
| 126 | 126 | sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
| 127 | 127 | ); |
| 128 | - } elseif (!$this->isWpValid()) { |
|
| 128 | + } |
|
| 129 | + elseif (!$this->isWpValid()) { |
|
| 129 | 130 | printf($noticeTemplate, |
| 130 | 131 | sprintf($messages['notice'], $pluginName), |
| 131 | 132 | sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
@@ -8,141 +8,141 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class GL_Plugin_Check_v4 |
| 10 | 10 | { |
| 11 | - const MIN_PHP_VERSION = '5.6.0'; |
|
| 12 | - const MIN_WORDPRESS_VERSION = '4.7.0'; |
|
| 11 | + const MIN_PHP_VERSION = '5.6.0'; |
|
| 12 | + const MIN_WORDPRESS_VERSION = '4.7.0'; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - public $versions; |
|
| 14 | + /** |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + public $versions; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $file; |
|
| 19 | + /** |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $file; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param string $file |
|
| 26 | - */ |
|
| 27 | - public function __construct($file) |
|
| 28 | - { |
|
| 29 | - $this->file = realpath($file); |
|
| 30 | - $versionRequirements = get_file_data($this->file, [ |
|
| 31 | - 'php' => 'Requires PHP', |
|
| 32 | - 'wordpress' => 'Requires at least', |
|
| 33 | - ]); |
|
| 34 | - $this->versions = wp_parse_args(array_filter($versionRequirements), [ |
|
| 35 | - 'php' => static::MIN_PHP_VERSION, |
|
| 36 | - 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
| 37 | - ]); |
|
| 38 | - } |
|
| 24 | + /** |
|
| 25 | + * @param string $file |
|
| 26 | + */ |
|
| 27 | + public function __construct($file) |
|
| 28 | + { |
|
| 29 | + $this->file = realpath($file); |
|
| 30 | + $versionRequirements = get_file_data($this->file, [ |
|
| 31 | + 'php' => 'Requires PHP', |
|
| 32 | + 'wordpress' => 'Requires at least', |
|
| 33 | + ]); |
|
| 34 | + $this->versions = wp_parse_args(array_filter($versionRequirements), [ |
|
| 35 | + 'php' => static::MIN_PHP_VERSION, |
|
| 36 | + 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
| 37 | + ]); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @return bool |
|
| 42 | - */ |
|
| 43 | - public function canProceed() |
|
| 44 | - { |
|
| 45 | - if ($this->isValid()) { |
|
| 46 | - return true; |
|
| 47 | - } |
|
| 48 | - add_action('activated_plugin', [$this, 'deactivate']); |
|
| 49 | - add_action('admin_notices', [$this, 'deactivate']); |
|
| 50 | - return false; |
|
| 51 | - } |
|
| 40 | + /** |
|
| 41 | + * @return bool |
|
| 42 | + */ |
|
| 43 | + public function canProceed() |
|
| 44 | + { |
|
| 45 | + if ($this->isValid()) { |
|
| 46 | + return true; |
|
| 47 | + } |
|
| 48 | + add_action('activated_plugin', [$this, 'deactivate']); |
|
| 49 | + add_action('admin_notices', [$this, 'deactivate']); |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return bool |
|
| 55 | - */ |
|
| 56 | - public function isPhpValid() |
|
| 57 | - { |
|
| 58 | - return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
| 59 | - } |
|
| 53 | + /** |
|
| 54 | + * @return bool |
|
| 55 | + */ |
|
| 56 | + public function isPhpValid() |
|
| 57 | + { |
|
| 58 | + return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @return bool |
|
| 63 | - */ |
|
| 64 | - public function isValid() |
|
| 65 | - { |
|
| 66 | - return $this->isPhpValid() && $this->isWpValid(); |
|
| 67 | - } |
|
| 61 | + /** |
|
| 62 | + * @return bool |
|
| 63 | + */ |
|
| 64 | + public function isValid() |
|
| 65 | + { |
|
| 66 | + return $this->isPhpValid() && $this->isWpValid(); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @return bool |
|
| 71 | - */ |
|
| 72 | - public function isWpValid() |
|
| 73 | - { |
|
| 74 | - global $wp_version; |
|
| 75 | - return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
| 76 | - } |
|
| 69 | + /** |
|
| 70 | + * @return bool |
|
| 71 | + */ |
|
| 72 | + public function isWpValid() |
|
| 73 | + { |
|
| 74 | + global $wp_version; |
|
| 75 | + return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @param string $plugin |
|
| 80 | - * @return void |
|
| 81 | - */ |
|
| 82 | - public function deactivate($plugin) |
|
| 83 | - { |
|
| 84 | - if ($this->isValid()) { |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - $pluginSlug = plugin_basename($this->file); |
|
| 88 | - if ($plugin == $pluginSlug) { |
|
| 89 | - $this->redirect(); //exit |
|
| 90 | - } |
|
| 91 | - $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin'); |
|
| 92 | - deactivate_plugins($pluginSlug); |
|
| 93 | - $this->printNotice($pluginData['name']); |
|
| 94 | - } |
|
| 78 | + /** |
|
| 79 | + * @param string $plugin |
|
| 80 | + * @return void |
|
| 81 | + */ |
|
| 82 | + public function deactivate($plugin) |
|
| 83 | + { |
|
| 84 | + if ($this->isValid()) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + $pluginSlug = plugin_basename($this->file); |
|
| 88 | + if ($plugin == $pluginSlug) { |
|
| 89 | + $this->redirect(); //exit |
|
| 90 | + } |
|
| 91 | + $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin'); |
|
| 92 | + deactivate_plugins($pluginSlug); |
|
| 93 | + $this->printNotice($pluginData['name']); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * @return array |
|
| 98 | - */ |
|
| 99 | - protected function getMessages() |
|
| 100 | - { |
|
| 101 | - return [ |
|
| 102 | - 'notice' => __('The %s plugin was deactivated.', 'site-reviews'), |
|
| 103 | - 'php_version' => __('PHP version', 'site-reviews'), |
|
| 104 | - 'rollback' => __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'), |
|
| 105 | - 'update_php' => __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'), |
|
| 106 | - 'update_wp' => __('Update WordPress', 'site-reviews'), |
|
| 107 | - 'wp_version' => __('WordPress version', 'site-reviews'), |
|
| 108 | - 'wrong_version' => __('This plugin requires %s or greater in order to work properly.', 'site-reviews'), |
|
| 109 | - ]; |
|
| 110 | - } |
|
| 96 | + /** |
|
| 97 | + * @return array |
|
| 98 | + */ |
|
| 99 | + protected function getMessages() |
|
| 100 | + { |
|
| 101 | + return [ |
|
| 102 | + 'notice' => __('The %s plugin was deactivated.', 'site-reviews'), |
|
| 103 | + 'php_version' => __('PHP version', 'site-reviews'), |
|
| 104 | + 'rollback' => __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'), |
|
| 105 | + 'update_php' => __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'), |
|
| 106 | + 'update_wp' => __('Update WordPress', 'site-reviews'), |
|
| 107 | + 'wp_version' => __('WordPress version', 'site-reviews'), |
|
| 108 | + 'wrong_version' => __('This plugin requires %s or greater in order to work properly.', 'site-reviews'), |
|
| 109 | + ]; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * @param string $pluginName |
|
| 114 | - * @return void |
|
| 115 | - */ |
|
| 116 | - protected function printNotice($pluginName) |
|
| 117 | - { |
|
| 118 | - $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
| 119 | - $messages = $this->getMessages(); |
|
| 120 | - $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
| 121 | - if (!$this->isPhpValid()) { |
|
| 122 | - printf($noticeTemplate, |
|
| 123 | - sprintf($messages['notice'], $pluginName), |
|
| 124 | - sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
|
| 125 | - sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
| 126 | - ); |
|
| 127 | - } elseif (!$this->isWpValid()) { |
|
| 128 | - printf($noticeTemplate, |
|
| 129 | - sprintf($messages['notice'], $pluginName), |
|
| 130 | - sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
|
| 131 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp']) |
|
| 132 | - ); |
|
| 133 | - } |
|
| 134 | - } |
|
| 112 | + /** |
|
| 113 | + * @param string $pluginName |
|
| 114 | + * @return void |
|
| 115 | + */ |
|
| 116 | + protected function printNotice($pluginName) |
|
| 117 | + { |
|
| 118 | + $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
| 119 | + $messages = $this->getMessages(); |
|
| 120 | + $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
| 121 | + if (!$this->isPhpValid()) { |
|
| 122 | + printf($noticeTemplate, |
|
| 123 | + sprintf($messages['notice'], $pluginName), |
|
| 124 | + sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
|
| 125 | + sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
| 126 | + ); |
|
| 127 | + } elseif (!$this->isWpValid()) { |
|
| 128 | + printf($noticeTemplate, |
|
| 129 | + sprintf($messages['notice'], $pluginName), |
|
| 130 | + sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
|
| 131 | + $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp']) |
|
| 132 | + ); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * @return void |
|
| 138 | - */ |
|
| 139 | - protected function redirect() |
|
| 140 | - { |
|
| 141 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
| 142 | - filter_input(INPUT_GET, 'plugin_status'), |
|
| 143 | - filter_input(INPUT_GET, 'paged'), |
|
| 144 | - filter_input(INPUT_GET, 's') |
|
| 145 | - ))); |
|
| 146 | - exit; |
|
| 147 | - } |
|
| 136 | + /** |
|
| 137 | + * @return void |
|
| 138 | + */ |
|
| 139 | + protected function redirect() |
|
| 140 | + { |
|
| 141 | + wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
| 142 | + filter_input(INPUT_GET, 'plugin_status'), |
|
| 143 | + filter_input(INPUT_GET, 'paged'), |
|
| 144 | + filter_input(INPUT_GET, 's') |
|
| 145 | + ))); |
|
| 146 | + exit; |
|
| 147 | + } |
|
| 148 | 148 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -defined('WPINC') || die; |
|
| 3 | +defined( 'WPINC' ) || die; |
|
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * Check for minimum system requirments on plugin activation. |
@@ -24,17 +24,17 @@ discard block |
||
| 24 | 24 | /** |
| 25 | 25 | * @param string $file |
| 26 | 26 | */ |
| 27 | - public function __construct($file) |
|
| 27 | + public function __construct( $file ) |
|
| 28 | 28 | { |
| 29 | - $this->file = realpath($file); |
|
| 30 | - $versionRequirements = get_file_data($this->file, [ |
|
| 29 | + $this->file = realpath( $file ); |
|
| 30 | + $versionRequirements = get_file_data( $this->file, [ |
|
| 31 | 31 | 'php' => 'Requires PHP', |
| 32 | 32 | 'wordpress' => 'Requires at least', |
| 33 | - ]); |
|
| 34 | - $this->versions = wp_parse_args(array_filter($versionRequirements), [ |
|
| 33 | + ] ); |
|
| 34 | + $this->versions = wp_parse_args( array_filter( $versionRequirements ), [ |
|
| 35 | 35 | 'php' => static::MIN_PHP_VERSION, |
| 36 | 36 | 'wordpress' => static::MIN_WORDPRESS_VERSION, |
| 37 | - ]); |
|
| 37 | + ] ); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function canProceed() |
| 44 | 44 | { |
| 45 | - if ($this->isValid()) { |
|
| 45 | + if( $this->isValid() ) { |
|
| 46 | 46 | return true; |
| 47 | 47 | } |
| 48 | - add_action('activated_plugin', [$this, 'deactivate']); |
|
| 49 | - add_action('admin_notices', [$this, 'deactivate']); |
|
| 48 | + add_action( 'activated_plugin', [$this, 'deactivate'] ); |
|
| 49 | + add_action( 'admin_notices', [$this, 'deactivate'] ); |
|
| 50 | 50 | return false; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function isPhpValid() |
| 57 | 57 | { |
| 58 | - return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
| 58 | + return !version_compare( PHP_VERSION, $this->versions['php'], '<' ); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -72,25 +72,25 @@ discard block |
||
| 72 | 72 | public function isWpValid() |
| 73 | 73 | { |
| 74 | 74 | global $wp_version; |
| 75 | - return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
| 75 | + return !version_compare( $wp_version, $this->versions['wordpress'], '<' ); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * @param string $plugin |
| 80 | 80 | * @return void |
| 81 | 81 | */ |
| 82 | - public function deactivate($plugin) |
|
| 82 | + public function deactivate( $plugin ) |
|
| 83 | 83 | { |
| 84 | - if ($this->isValid()) { |
|
| 84 | + if( $this->isValid() ) { |
|
| 85 | 85 | return; |
| 86 | 86 | } |
| 87 | - $pluginSlug = plugin_basename($this->file); |
|
| 88 | - if ($plugin == $pluginSlug) { |
|
| 87 | + $pluginSlug = plugin_basename( $this->file ); |
|
| 88 | + if( $plugin == $pluginSlug ) { |
|
| 89 | 89 | $this->redirect(); //exit |
| 90 | 90 | } |
| 91 | - $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin'); |
|
| 92 | - deactivate_plugins($pluginSlug); |
|
| 93 | - $this->printNotice($pluginData['name']); |
|
| 91 | + $pluginData = get_file_data( $this->file, ['name' => 'Plugin Name'], 'plugin' ); |
|
| 92 | + deactivate_plugins( $pluginSlug ); |
|
| 93 | + $this->printNotice( $pluginData['name'] ); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -99,13 +99,13 @@ discard block |
||
| 99 | 99 | protected function getMessages() |
| 100 | 100 | { |
| 101 | 101 | return [ |
| 102 | - 'notice' => __('The %s plugin was deactivated.', 'site-reviews'), |
|
| 103 | - 'php_version' => __('PHP version', 'site-reviews'), |
|
| 104 | - 'rollback' => __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'), |
|
| 105 | - 'update_php' => __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'), |
|
| 106 | - 'update_wp' => __('Update WordPress', 'site-reviews'), |
|
| 107 | - 'wp_version' => __('WordPress version', 'site-reviews'), |
|
| 108 | - 'wrong_version' => __('This plugin requires %s or greater in order to work properly.', 'site-reviews'), |
|
| 102 | + 'notice' => __( 'The %s plugin was deactivated.', 'site-reviews' ), |
|
| 103 | + 'php_version' => __( 'PHP version', 'site-reviews' ), |
|
| 104 | + 'rollback' => __( 'You can use the %s plugin to restore %s to the previous version.', 'site-reviews' ), |
|
| 105 | + 'update_php' => __( 'Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews' ), |
|
| 106 | + 'update_wp' => __( 'Update WordPress', 'site-reviews' ), |
|
| 107 | + 'wp_version' => __( 'WordPress version', 'site-reviews' ), |
|
| 108 | + 'wrong_version' => __( 'This plugin requires %s or greater in order to work properly.', 'site-reviews' ), |
|
| 109 | 109 | ]; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -113,22 +113,22 @@ discard block |
||
| 113 | 113 | * @param string $pluginName |
| 114 | 114 | * @return void |
| 115 | 115 | */ |
| 116 | - protected function printNotice($pluginName) |
|
| 116 | + protected function printNotice( $pluginName ) |
|
| 117 | 117 | { |
| 118 | 118 | $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
| 119 | 119 | $messages = $this->getMessages(); |
| 120 | - $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
| 121 | - if (!$this->isPhpValid()) { |
|
| 122 | - printf($noticeTemplate, |
|
| 123 | - sprintf($messages['notice'], $pluginName), |
|
| 124 | - sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
|
| 125 | - sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
| 120 | + $rollbackMessage = sprintf( '<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName ); |
|
| 121 | + if( !$this->isPhpValid() ) { |
|
| 122 | + printf( $noticeTemplate, |
|
| 123 | + sprintf( $messages['notice'], $pluginName ), |
|
| 124 | + sprintf( $messages['wrong_version'], $messages['php_version'].' '.$this->versions['php'] ), |
|
| 125 | + sprintf( $messages['update_php'], PHP_VERSION ).'</p><p>'.$rollbackMessage |
|
| 126 | 126 | ); |
| 127 | - } elseif (!$this->isWpValid()) { |
|
| 128 | - printf($noticeTemplate, |
|
| 129 | - sprintf($messages['notice'], $pluginName), |
|
| 130 | - sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
|
| 131 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp']) |
|
| 127 | + } elseif( !$this->isWpValid() ) { |
|
| 128 | + printf( $noticeTemplate, |
|
| 129 | + sprintf( $messages['notice'], $pluginName ), |
|
| 130 | + sprintf( $messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress'] ), |
|
| 131 | + $rollbackMessage.'</p><p>'.sprintf( '<a href="%s">%s</a>', admin_url( 'update-core.php' ), $messages['update_wp'] ) |
|
| 132 | 132 | ); |
| 133 | 133 | } |
| 134 | 134 | } |
@@ -138,11 +138,11 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | protected function redirect() |
| 140 | 140 | { |
| 141 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
| 142 | - filter_input(INPUT_GET, 'plugin_status'), |
|
| 143 | - filter_input(INPUT_GET, 'paged'), |
|
| 144 | - filter_input(INPUT_GET, 's') |
|
| 145 | - ))); |
|
| 141 | + wp_safe_redirect( self_admin_url( sprintf( 'plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
| 142 | + filter_input( INPUT_GET, 'plugin_status' ), |
|
| 143 | + filter_input( INPUT_GET, 'paged' ), |
|
| 144 | + filter_input( INPUT_GET, 's' ) |
|
| 145 | + ) ) ); |
|
| 146 | 146 | exit; |
| 147 | 147 | } |
| 148 | 148 | } |
@@ -1,20 +1,20 @@ |
||
| 1 | -<?php defined('WPINC') || die; ?> |
|
| 1 | +<?php defined( 'WPINC' ) || die; ?> |
|
| 2 | 2 | |
| 3 | 3 | <div class="wrap"> |
| 4 | 4 | <h1 class="wp-heading-inline"> |
| 5 | - <?= esc_html(get_admin_page_title()); ?> |
|
| 6 | - <a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=welcome'); ?>" class="page-title-action"><?= __('About', 'site-reviews'); ?></a> |
|
| 5 | + <?= esc_html( get_admin_page_title() ); ?> |
|
| 6 | + <a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=welcome' ); ?>" class="page-title-action"><?= __( 'About', 'site-reviews' ); ?></a> |
|
| 7 | 7 | </h1> |
| 8 | 8 | <?= $notices; ?> |
| 9 | - <p><?= __('Click an active tab to expand/collapse all sections.', 'site-reviews'); ?></p> |
|
| 9 | + <p><?= __( 'Click an active tab to expand/collapse all sections.', 'site-reviews' ); ?></p> |
|
| 10 | 10 | <h2 class="glsr-nav-tab-wrapper nav-tab-wrapper"> |
| 11 | - <?php foreach ($tabs as $id => $title) : ?> |
|
| 11 | + <?php foreach( $tabs as $id => $title ) : ?> |
|
| 12 | 12 | <a class="glsr-nav-tab nav-tab" href="#<?= $id; ?>"><?= $title; ?></a> |
| 13 | 13 | <?php endforeach; ?> |
| 14 | 14 | </h2> |
| 15 | - <?php foreach ($tabs as $id => $title) : ?> |
|
| 15 | + <?php foreach( $tabs as $id => $title ) : ?> |
|
| 16 | 16 | <div class="glsr-nav-view ui-tabs-hide" id="<?= $id; ?>"> |
| 17 | - <?php glsr()->render('pages/documentation/'.$id, $data); ?> |
|
| 17 | + <?php glsr()->render( 'pages/documentation/'.$id, $data ); ?> |
|
| 18 | 18 | </div> |
| 19 | 19 | <?php endforeach; ?> |
| 20 | 20 | <input type="hidden" name="_active_tab"> |
@@ -1,23 +1,23 @@ |
||
| 1 | -<?php defined('WPINC') || die; ?> |
|
| 1 | +<?php defined( 'WPINC' ) || die; ?> |
|
| 2 | 2 | |
| 3 | 3 | <div class="glsr-welcome wrap about-wrap about-wrap-content"> |
| 4 | 4 | <h1>Welcome to <?= glsr()->name; ?></h1> |
| 5 | 5 | <div class="about-text">Site Reviews is a free WordPress review plugin with advanced features that makes it easy to manage reviews on your website. Follow the instructions below to get started!</div> |
| 6 | 6 | <div class="wp-badge">Version <?= glsr()->version; ?></div> |
| 7 | 7 | <p class="about-buttons"> |
| 8 | - <a class="button" href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation'); ?>">Documentation</a> |
|
| 8 | + <a class="button" href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation' ); ?>">Documentation</a> |
|
| 9 | 9 | <a class="button" href="https://wordpress.org/support/plugin/site-reviews/">Support</a> |
| 10 | 10 | <a target="_blank" class="button" href="https://www.facebook.com/sharer/sharer.php?u=https%3A//geminilabs.io/site-reviews"><span class="dashicons dashicons-facebook-alt"></span> Share</a> |
| 11 | 11 | <a target="_blank" class="button" href="https://twitter.com/intent/tweet?text=Site Reviews is a fantastic WordPress review plugin with advanced features that makes it easy to manage reviews on your website.&url=https://geminilabs.io/site-reviews&hashtags=WordPress,reviewplugins,"><span class="dashicons dashicons-twitter"></span> Tweet</a> |
| 12 | 12 | </p> |
| 13 | 13 | <nav class="glsr-nav-tab-wrapper nav-tab-wrapper"> |
| 14 | - <?php foreach ($tabs as $id => $title) : ?> |
|
| 14 | + <?php foreach( $tabs as $id => $title ) : ?> |
|
| 15 | 15 | <a class="glsr-nav-tab nav-tab" href="#<?= $id; ?>"><?= $title; ?></a> |
| 16 | 16 | <?php endforeach; ?> |
| 17 | 17 | </nav> |
| 18 | - <?php foreach ($tabs as $id => $title) : ?> |
|
| 18 | + <?php foreach( $tabs as $id => $title ) : ?> |
|
| 19 | 19 | <div class="glsr-nav-view ui-tabs-hide" id="<?= $id; ?>"> |
| 20 | - <?php $template->render('pages/welcome/'.$id, $data); ?> |
|
| 20 | + <?php $template->render( 'pages/welcome/'.$id, $data ); ?> |
|
| 21 | 21 | </div> |
| 22 | 22 | <?php endforeach; ?> |
| 23 | 23 | <input type="hidden" name="_active_tab"> |
@@ -134,7 +134,8 @@ discard block |
||
| 134 | 134 | $integration->pluginName |
| 135 | 135 | )); |
| 136 | 136 | return false; |
| 137 | - } elseif (!$integration->isSupported()) { |
|
| 137 | + } |
|
| 138 | + elseif (!$integration->isSupported()) { |
|
| 138 | 139 | glsr(Notice::class)->addError(sprintf( |
| 139 | 140 | __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
| 140 | 141 | $integration->pluginName, |
@@ -161,7 +162,8 @@ discard block |
||
| 161 | 162 | if (!$updater->isLicenseValid()) { |
| 162 | 163 | throw new Exception('Invalid license: '.$license.' ('.$addon->id.')'); |
| 163 | 164 | } |
| 164 | - } catch (Exception $e) { |
|
| 165 | + } |
|
| 166 | + catch (Exception $e) { |
|
| 165 | 167 | $license = ''; |
| 166 | 168 | glsr_log()->debug($e->getMessage()); |
| 167 | 169 | glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews')); |
@@ -12,163 +12,163 @@ |
||
| 12 | 12 | |
| 13 | 13 | class SettingsController extends Controller |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @param mixed $input |
|
| 17 | - * @return array |
|
| 18 | - * @callback register_setting |
|
| 19 | - */ |
|
| 20 | - public function callbackRegisterSettings($input) |
|
| 21 | - { |
|
| 22 | - $settings = Arr::consolidateArray($input); |
|
| 23 | - if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
| 24 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
| 25 | - $options = $this->sanitizeGeneral($input, $options); |
|
| 26 | - $options = $this->sanitizeLicenses($input, $options); |
|
| 27 | - $options = $this->sanitizeSubmissions($input, $options); |
|
| 28 | - $options = $this->sanitizeTranslations($input, $options); |
|
| 29 | - $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
| 30 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
| 31 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
| 32 | - } |
|
| 33 | - return $options; |
|
| 34 | - } |
|
| 35 | - return $input; |
|
| 36 | - } |
|
| 15 | + /** |
|
| 16 | + * @param mixed $input |
|
| 17 | + * @return array |
|
| 18 | + * @callback register_setting |
|
| 19 | + */ |
|
| 20 | + public function callbackRegisterSettings($input) |
|
| 21 | + { |
|
| 22 | + $settings = Arr::consolidateArray($input); |
|
| 23 | + if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
| 24 | + $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
| 25 | + $options = $this->sanitizeGeneral($input, $options); |
|
| 26 | + $options = $this->sanitizeLicenses($input, $options); |
|
| 27 | + $options = $this->sanitizeSubmissions($input, $options); |
|
| 28 | + $options = $this->sanitizeTranslations($input, $options); |
|
| 29 | + $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
| 30 | + if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
| 31 | + glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
| 32 | + } |
|
| 33 | + return $options; |
|
| 34 | + } |
|
| 35 | + return $input; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @return void |
|
| 40 | - * @action admin_init |
|
| 41 | - */ |
|
| 42 | - public function registerSettings() |
|
| 43 | - { |
|
| 44 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
| 45 | - 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
| 46 | - ]); |
|
| 47 | - } |
|
| 38 | + /** |
|
| 39 | + * @return void |
|
| 40 | + * @action admin_init |
|
| 41 | + */ |
|
| 42 | + public function registerSettings() |
|
| 43 | + { |
|
| 44 | + register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
| 45 | + 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
| 46 | + ]); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @return array |
|
| 51 | - */ |
|
| 52 | - protected function sanitizeGeneral(array $input, array $options) |
|
| 53 | - { |
|
| 54 | - $key = 'settings.general'; |
|
| 55 | - $inputForm = Arr::get($input, $key); |
|
| 56 | - if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) { |
|
| 57 | - $options = Arr::set($options, $key.'.multilingual', ''); |
|
| 58 | - } |
|
| 59 | - if ('' == trim(Arr::get($inputForm, 'notification_message'))) { |
|
| 60 | - $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message'); |
|
| 61 | - $options = Arr::set($options, $key.'.notification_message', $defaultValue); |
|
| 62 | - } |
|
| 63 | - $defaultValue = Arr::get($inputForm, 'notifications', []); |
|
| 64 | - $options = Arr::set($options, $key.'.notifications', $defaultValue); |
|
| 65 | - return $options; |
|
| 66 | - } |
|
| 49 | + /** |
|
| 50 | + * @return array |
|
| 51 | + */ |
|
| 52 | + protected function sanitizeGeneral(array $input, array $options) |
|
| 53 | + { |
|
| 54 | + $key = 'settings.general'; |
|
| 55 | + $inputForm = Arr::get($input, $key); |
|
| 56 | + if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) { |
|
| 57 | + $options = Arr::set($options, $key.'.multilingual', ''); |
|
| 58 | + } |
|
| 59 | + if ('' == trim(Arr::get($inputForm, 'notification_message'))) { |
|
| 60 | + $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message'); |
|
| 61 | + $options = Arr::set($options, $key.'.notification_message', $defaultValue); |
|
| 62 | + } |
|
| 63 | + $defaultValue = Arr::get($inputForm, 'notifications', []); |
|
| 64 | + $options = Arr::set($options, $key.'.notifications', $defaultValue); |
|
| 65 | + return $options; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @return array |
|
| 70 | - */ |
|
| 71 | - protected function sanitizeLicenses(array $input, array $options) |
|
| 72 | - { |
|
| 73 | - $key = 'settings.licenses'; |
|
| 74 | - $licenses = Arr::consolidateArray(Arr::get($input, $key)); |
|
| 75 | - foreach ($licenses as $slug => &$license) { |
|
| 76 | - if (empty($license)) { |
|
| 77 | - continue; |
|
| 78 | - } |
|
| 79 | - $license = $this->verifyLicense($license, $slug); |
|
| 80 | - } |
|
| 81 | - $options = Arr::set($options, $key, $licenses); |
|
| 82 | - return $options; |
|
| 83 | - } |
|
| 68 | + /** |
|
| 69 | + * @return array |
|
| 70 | + */ |
|
| 71 | + protected function sanitizeLicenses(array $input, array $options) |
|
| 72 | + { |
|
| 73 | + $key = 'settings.licenses'; |
|
| 74 | + $licenses = Arr::consolidateArray(Arr::get($input, $key)); |
|
| 75 | + foreach ($licenses as $slug => &$license) { |
|
| 76 | + if (empty($license)) { |
|
| 77 | + continue; |
|
| 78 | + } |
|
| 79 | + $license = $this->verifyLicense($license, $slug); |
|
| 80 | + } |
|
| 81 | + $options = Arr::set($options, $key, $licenses); |
|
| 82 | + return $options; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @return array |
|
| 87 | - */ |
|
| 88 | - protected function sanitizeSubmissions(array $input, array $options) |
|
| 89 | - { |
|
| 90 | - $key = 'settings.submissions'; |
|
| 91 | - $inputForm = Arr::get($input, $key); |
|
| 92 | - $defaultValue = isset($inputForm['required']) |
|
| 93 | - ? $inputForm['required'] |
|
| 94 | - : []; |
|
| 95 | - $options = Arr::set($options, $key.'.required', $defaultValue); |
|
| 96 | - return $options; |
|
| 97 | - } |
|
| 85 | + /** |
|
| 86 | + * @return array |
|
| 87 | + */ |
|
| 88 | + protected function sanitizeSubmissions(array $input, array $options) |
|
| 89 | + { |
|
| 90 | + $key = 'settings.submissions'; |
|
| 91 | + $inputForm = Arr::get($input, $key); |
|
| 92 | + $defaultValue = isset($inputForm['required']) |
|
| 93 | + ? $inputForm['required'] |
|
| 94 | + : []; |
|
| 95 | + $options = Arr::set($options, $key.'.required', $defaultValue); |
|
| 96 | + return $options; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @return array |
|
| 101 | - */ |
|
| 102 | - protected function sanitizeTranslations(array $input, array $options) |
|
| 103 | - { |
|
| 104 | - $key = 'settings.strings'; |
|
| 105 | - $inputForm = Arr::consolidateArray(Arr::get($input, $key)); |
|
| 106 | - if (!empty($inputForm)) { |
|
| 107 | - $options = Arr::set($options, $key, array_values(array_filter($inputForm))); |
|
| 108 | - $allowedTags = [ |
|
| 109 | - 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
| 110 | - 'span' => ['class' => []], |
|
| 111 | - ]; |
|
| 112 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
| 113 | - if (isset($string['s2'])) { |
|
| 114 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
| 115 | - } |
|
| 116 | - if (isset($string['p2'])) { |
|
| 117 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
| 118 | - } |
|
| 119 | - }); |
|
| 120 | - } |
|
| 121 | - return $options; |
|
| 122 | - } |
|
| 99 | + /** |
|
| 100 | + * @return array |
|
| 101 | + */ |
|
| 102 | + protected function sanitizeTranslations(array $input, array $options) |
|
| 103 | + { |
|
| 104 | + $key = 'settings.strings'; |
|
| 105 | + $inputForm = Arr::consolidateArray(Arr::get($input, $key)); |
|
| 106 | + if (!empty($inputForm)) { |
|
| 107 | + $options = Arr::set($options, $key, array_values(array_filter($inputForm))); |
|
| 108 | + $allowedTags = [ |
|
| 109 | + 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
| 110 | + 'span' => ['class' => []], |
|
| 111 | + ]; |
|
| 112 | + array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
| 113 | + if (isset($string['s2'])) { |
|
| 114 | + $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
| 115 | + } |
|
| 116 | + if (isset($string['p2'])) { |
|
| 117 | + $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
| 118 | + } |
|
| 119 | + }); |
|
| 120 | + } |
|
| 121 | + return $options; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * @param string $integrationSlug |
|
| 126 | - * @return bool |
|
| 127 | - */ |
|
| 128 | - protected function hasMultilingualIntegration($integrationSlug) |
|
| 129 | - { |
|
| 130 | - $integration = glsr(Multilingual::class)->getIntegration($integrationSlug); |
|
| 131 | - if (!$integration) { |
|
| 132 | - return false; |
|
| 133 | - } |
|
| 134 | - if (!$integration->isActive()) { |
|
| 135 | - glsr(Notice::class)->addError(sprintf( |
|
| 136 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
| 137 | - $integration->pluginName |
|
| 138 | - )); |
|
| 139 | - return false; |
|
| 140 | - } elseif (!$integration->isSupported()) { |
|
| 141 | - glsr(Notice::class)->addError(sprintf( |
|
| 142 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
| 143 | - $integration->pluginName, |
|
| 144 | - $integration->supportedVersion |
|
| 145 | - )); |
|
| 146 | - return false; |
|
| 147 | - } |
|
| 148 | - return true; |
|
| 149 | - } |
|
| 124 | + /** |
|
| 125 | + * @param string $integrationSlug |
|
| 126 | + * @return bool |
|
| 127 | + */ |
|
| 128 | + protected function hasMultilingualIntegration($integrationSlug) |
|
| 129 | + { |
|
| 130 | + $integration = glsr(Multilingual::class)->getIntegration($integrationSlug); |
|
| 131 | + if (!$integration) { |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 134 | + if (!$integration->isActive()) { |
|
| 135 | + glsr(Notice::class)->addError(sprintf( |
|
| 136 | + __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
| 137 | + $integration->pluginName |
|
| 138 | + )); |
|
| 139 | + return false; |
|
| 140 | + } elseif (!$integration->isSupported()) { |
|
| 141 | + glsr(Notice::class)->addError(sprintf( |
|
| 142 | + __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
| 143 | + $integration->pluginName, |
|
| 144 | + $integration->supportedVersion |
|
| 145 | + )); |
|
| 146 | + return false; |
|
| 147 | + } |
|
| 148 | + return true; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * @param string $license |
|
| 153 | - * @param string $slug |
|
| 154 | - * @return string |
|
| 155 | - */ |
|
| 156 | - protected function verifyLicense($license, $slug) |
|
| 157 | - { |
|
| 158 | - try { |
|
| 159 | - $addon = glsr($slug); |
|
| 160 | - $updater = new Updater($addon->update_url, $addon->file, [ |
|
| 161 | - 'license' => $license, |
|
| 162 | - 'testedTo' => $addon->testedTo, |
|
| 163 | - ]); |
|
| 164 | - if (!$updater->isLicenseValid()) { |
|
| 165 | - throw new Exception('Invalid license: '.$license.' ('.$addon->id.')'); |
|
| 166 | - } |
|
| 167 | - } catch (Exception $e) { |
|
| 168 | - $license = ''; |
|
| 169 | - glsr_log()->debug($e->getMessage()); |
|
| 170 | - glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews')); |
|
| 171 | - } |
|
| 172 | - return $license; |
|
| 173 | - } |
|
| 151 | + /** |
|
| 152 | + * @param string $license |
|
| 153 | + * @param string $slug |
|
| 154 | + * @return string |
|
| 155 | + */ |
|
| 156 | + protected function verifyLicense($license, $slug) |
|
| 157 | + { |
|
| 158 | + try { |
|
| 159 | + $addon = glsr($slug); |
|
| 160 | + $updater = new Updater($addon->update_url, $addon->file, [ |
|
| 161 | + 'license' => $license, |
|
| 162 | + 'testedTo' => $addon->testedTo, |
|
| 163 | + ]); |
|
| 164 | + if (!$updater->isLicenseValid()) { |
|
| 165 | + throw new Exception('Invalid license: '.$license.' ('.$addon->id.')'); |
|
| 166 | + } |
|
| 167 | + } catch (Exception $e) { |
|
| 168 | + $license = ''; |
|
| 169 | + glsr_log()->debug($e->getMessage()); |
|
| 170 | + glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews')); |
|
| 171 | + } |
|
| 172 | + return $license; |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -17,18 +17,18 @@ discard block |
||
| 17 | 17 | * @return array |
| 18 | 18 | * @callback register_setting |
| 19 | 19 | */ |
| 20 | - public function callbackRegisterSettings($input) |
|
| 20 | + public function callbackRegisterSettings( $input ) |
|
| 21 | 21 | { |
| 22 | - $settings = Arr::consolidateArray($input); |
|
| 23 | - if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
| 24 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
| 25 | - $options = $this->sanitizeGeneral($input, $options); |
|
| 26 | - $options = $this->sanitizeLicenses($input, $options); |
|
| 27 | - $options = $this->sanitizeSubmissions($input, $options); |
|
| 28 | - $options = $this->sanitizeTranslations($input, $options); |
|
| 29 | - $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
| 30 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
| 31 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
| 22 | + $settings = Arr::consolidateArray( $input ); |
|
| 23 | + if( 1 === count( $settings ) && array_key_exists( 'settings', $settings ) ) { |
|
| 24 | + $options = array_replace_recursive( glsr( OptionManager::class )->all(), $input ); |
|
| 25 | + $options = $this->sanitizeGeneral( $input, $options ); |
|
| 26 | + $options = $this->sanitizeLicenses( $input, $options ); |
|
| 27 | + $options = $this->sanitizeSubmissions( $input, $options ); |
|
| 28 | + $options = $this->sanitizeTranslations( $input, $options ); |
|
| 29 | + $options = apply_filters( 'site-reviews/settings/callback', $options, $settings ); |
|
| 30 | + if( filter_input( INPUT_POST, 'option_page' ) == Application::ID.'-settings' ) { |
|
| 31 | + glsr( Notice::class )->addSuccess( __( 'Settings updated.', 'site-reviews' ) ); |
|
| 32 | 32 | } |
| 33 | 33 | return $options; |
| 34 | 34 | } |
@@ -41,80 +41,80 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function registerSettings() |
| 43 | 43 | { |
| 44 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
| 44 | + register_setting( Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
| 45 | 45 | 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
| 46 | - ]); |
|
| 46 | + ] ); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * @return array |
| 51 | 51 | */ |
| 52 | - protected function sanitizeGeneral(array $input, array $options) |
|
| 52 | + protected function sanitizeGeneral( array $input, array $options ) |
|
| 53 | 53 | { |
| 54 | 54 | $key = 'settings.general'; |
| 55 | - $inputForm = Arr::get($input, $key); |
|
| 56 | - if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) { |
|
| 57 | - $options = Arr::set($options, $key.'.multilingual', ''); |
|
| 55 | + $inputForm = Arr::get( $input, $key ); |
|
| 56 | + if( !$this->hasMultilingualIntegration( Arr::get( $inputForm, 'multilingual' ) ) ) { |
|
| 57 | + $options = Arr::set( $options, $key.'.multilingual', '' ); |
|
| 58 | 58 | } |
| 59 | - if ('' == trim(Arr::get($inputForm, 'notification_message'))) { |
|
| 60 | - $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message'); |
|
| 61 | - $options = Arr::set($options, $key.'.notification_message', $defaultValue); |
|
| 59 | + if( '' == trim( Arr::get( $inputForm, 'notification_message' ) ) ) { |
|
| 60 | + $defaultValue = Arr::get( glsr()->defaults, $key.'.notification_message' ); |
|
| 61 | + $options = Arr::set( $options, $key.'.notification_message', $defaultValue ); |
|
| 62 | 62 | } |
| 63 | - $defaultValue = Arr::get($inputForm, 'notifications', []); |
|
| 64 | - $options = Arr::set($options, $key.'.notifications', $defaultValue); |
|
| 63 | + $defaultValue = Arr::get( $inputForm, 'notifications', [] ); |
|
| 64 | + $options = Arr::set( $options, $key.'.notifications', $defaultValue ); |
|
| 65 | 65 | return $options; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @return array |
| 70 | 70 | */ |
| 71 | - protected function sanitizeLicenses(array $input, array $options) |
|
| 71 | + protected function sanitizeLicenses( array $input, array $options ) |
|
| 72 | 72 | { |
| 73 | 73 | $key = 'settings.licenses'; |
| 74 | - $licenses = Arr::consolidateArray(Arr::get($input, $key)); |
|
| 75 | - foreach ($licenses as $slug => &$license) { |
|
| 76 | - if (empty($license)) { |
|
| 74 | + $licenses = Arr::consolidateArray( Arr::get( $input, $key ) ); |
|
| 75 | + foreach( $licenses as $slug => &$license ) { |
|
| 76 | + if( empty($license) ) { |
|
| 77 | 77 | continue; |
| 78 | 78 | } |
| 79 | - $license = $this->verifyLicense($license, $slug); |
|
| 79 | + $license = $this->verifyLicense( $license, $slug ); |
|
| 80 | 80 | } |
| 81 | - $options = Arr::set($options, $key, $licenses); |
|
| 81 | + $options = Arr::set( $options, $key, $licenses ); |
|
| 82 | 82 | return $options; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * @return array |
| 87 | 87 | */ |
| 88 | - protected function sanitizeSubmissions(array $input, array $options) |
|
| 88 | + protected function sanitizeSubmissions( array $input, array $options ) |
|
| 89 | 89 | { |
| 90 | 90 | $key = 'settings.submissions'; |
| 91 | - $inputForm = Arr::get($input, $key); |
|
| 91 | + $inputForm = Arr::get( $input, $key ); |
|
| 92 | 92 | $defaultValue = isset($inputForm['required']) |
| 93 | 93 | ? $inputForm['required'] |
| 94 | 94 | : []; |
| 95 | - $options = Arr::set($options, $key.'.required', $defaultValue); |
|
| 95 | + $options = Arr::set( $options, $key.'.required', $defaultValue ); |
|
| 96 | 96 | return $options; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * @return array |
| 101 | 101 | */ |
| 102 | - protected function sanitizeTranslations(array $input, array $options) |
|
| 102 | + protected function sanitizeTranslations( array $input, array $options ) |
|
| 103 | 103 | { |
| 104 | 104 | $key = 'settings.strings'; |
| 105 | - $inputForm = Arr::consolidateArray(Arr::get($input, $key)); |
|
| 106 | - if (!empty($inputForm)) { |
|
| 107 | - $options = Arr::set($options, $key, array_values(array_filter($inputForm))); |
|
| 105 | + $inputForm = Arr::consolidateArray( Arr::get( $input, $key ) ); |
|
| 106 | + if( !empty($inputForm) ) { |
|
| 107 | + $options = Arr::set( $options, $key, array_values( array_filter( $inputForm ) ) ); |
|
| 108 | 108 | $allowedTags = [ |
| 109 | 109 | 'a' => ['class' => [], 'href' => [], 'target' => []], |
| 110 | 110 | 'span' => ['class' => []], |
| 111 | 111 | ]; |
| 112 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
| 113 | - if (isset($string['s2'])) { |
|
| 114 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
| 112 | + array_walk( $options['settings']['strings'], function( &$string ) use ($allowedTags) { |
|
| 113 | + if( isset($string['s2']) ) { |
|
| 114 | + $string['s2'] = wp_kses( $string['s2'], $allowedTags ); |
|
| 115 | 115 | } |
| 116 | - if (isset($string['p2'])) { |
|
| 117 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
| 116 | + if( isset($string['p2']) ) { |
|
| 117 | + $string['p2'] = wp_kses( $string['p2'], $allowedTags ); |
|
| 118 | 118 | } |
| 119 | 119 | }); |
| 120 | 120 | } |
@@ -125,24 +125,24 @@ discard block |
||
| 125 | 125 | * @param string $integrationSlug |
| 126 | 126 | * @return bool |
| 127 | 127 | */ |
| 128 | - protected function hasMultilingualIntegration($integrationSlug) |
|
| 128 | + protected function hasMultilingualIntegration( $integrationSlug ) |
|
| 129 | 129 | { |
| 130 | - $integration = glsr(Multilingual::class)->getIntegration($integrationSlug); |
|
| 131 | - if (!$integration) { |
|
| 130 | + $integration = glsr( Multilingual::class )->getIntegration( $integrationSlug ); |
|
| 131 | + if( !$integration ) { |
|
| 132 | 132 | return false; |
| 133 | 133 | } |
| 134 | - if (!$integration->isActive()) { |
|
| 135 | - glsr(Notice::class)->addError(sprintf( |
|
| 136 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
| 134 | + if( !$integration->isActive() ) { |
|
| 135 | + glsr( Notice::class )->addError( sprintf( |
|
| 136 | + __( 'Please install/activate the %s plugin to enable integration.', 'site-reviews' ), |
|
| 137 | 137 | $integration->pluginName |
| 138 | - )); |
|
| 138 | + ) ); |
|
| 139 | 139 | return false; |
| 140 | - } elseif (!$integration->isSupported()) { |
|
| 141 | - glsr(Notice::class)->addError(sprintf( |
|
| 142 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
| 140 | + } elseif( !$integration->isSupported() ) { |
|
| 141 | + glsr( Notice::class )->addError( sprintf( |
|
| 142 | + __( 'Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews' ), |
|
| 143 | 143 | $integration->pluginName, |
| 144 | 144 | $integration->supportedVersion |
| 145 | - )); |
|
| 145 | + ) ); |
|
| 146 | 146 | return false; |
| 147 | 147 | } |
| 148 | 148 | return true; |
@@ -153,21 +153,21 @@ discard block |
||
| 153 | 153 | * @param string $slug |
| 154 | 154 | * @return string |
| 155 | 155 | */ |
| 156 | - protected function verifyLicense($license, $slug) |
|
| 156 | + protected function verifyLicense( $license, $slug ) |
|
| 157 | 157 | { |
| 158 | 158 | try { |
| 159 | - $addon = glsr($slug); |
|
| 160 | - $updater = new Updater($addon->update_url, $addon->file, [ |
|
| 159 | + $addon = glsr( $slug ); |
|
| 160 | + $updater = new Updater( $addon->update_url, $addon->file, [ |
|
| 161 | 161 | 'license' => $license, |
| 162 | 162 | 'testedTo' => $addon->testedTo, |
| 163 | - ]); |
|
| 164 | - if (!$updater->isLicenseValid()) { |
|
| 165 | - throw new Exception('Invalid license: '.$license.' ('.$addon->id.')'); |
|
| 163 | + ] ); |
|
| 164 | + if( !$updater->isLicenseValid() ) { |
|
| 165 | + throw new Exception( 'Invalid license: '.$license.' ('.$addon->id.')' ); |
|
| 166 | 166 | } |
| 167 | - } catch (Exception $e) { |
|
| 167 | + } catch( Exception $e ) { |
|
| 168 | 168 | $license = ''; |
| 169 | - glsr_log()->debug($e->getMessage()); |
|
| 170 | - glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews')); |
|
| 169 | + glsr_log()->debug( $e->getMessage() ); |
|
| 170 | + glsr( Notice::class )->addError( __( 'A license you entered was invalid.', 'site-reviews' ) ); |
|
| 171 | 171 | } |
| 172 | 172 | return $license; |
| 173 | 173 | } |
@@ -9,65 +9,65 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Reviews extends ArrayObject |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @var array |
|
| 14 | - */ |
|
| 15 | - public $args; |
|
| 12 | + /** |
|
| 13 | + * @var array |
|
| 14 | + */ |
|
| 15 | + public $args; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var int |
|
| 19 | - */ |
|
| 20 | - public $max_num_pages; |
|
| 17 | + /** |
|
| 18 | + * @var int |
|
| 19 | + */ |
|
| 20 | + public $max_num_pages; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - public $reviews; |
|
| 22 | + /** |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + public $reviews; |
|
| 26 | 26 | |
| 27 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
| 28 | - { |
|
| 29 | - $this->args = $args; |
|
| 30 | - $this->max_num_pages = $maxPageCount; |
|
| 31 | - $this->reviews = $reviews; |
|
| 32 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
| 33 | - } |
|
| 27 | + public function __construct(array $reviews, $maxPageCount, array $args) |
|
| 28 | + { |
|
| 29 | + $this->args = $args; |
|
| 30 | + $this->max_num_pages = $maxPageCount; |
|
| 31 | + $this->reviews = $reviews; |
|
| 32 | + parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function __toString() |
|
| 39 | - { |
|
| 40 | - return (string) $this->build(); |
|
| 41 | - } |
|
| 35 | + /** |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function __toString() |
|
| 39 | + { |
|
| 40 | + return (string) $this->build(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return ReviewsHtml |
|
| 45 | - */ |
|
| 46 | - public function build() |
|
| 47 | - { |
|
| 48 | - $args = glsr(SiteReviewsDefaults::class)->merge($this->args); |
|
| 49 | - return glsr(SiteReviewsPartial::class)->build($args, $this); |
|
| 50 | - } |
|
| 43 | + /** |
|
| 44 | + * @return ReviewsHtml |
|
| 45 | + */ |
|
| 46 | + public function build() |
|
| 47 | + { |
|
| 48 | + $args = glsr(SiteReviewsDefaults::class)->merge($this->args); |
|
| 49 | + return glsr(SiteReviewsPartial::class)->build($args, $this); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param mixed $key |
|
| 54 | - * @return mixed |
|
| 55 | - */ |
|
| 56 | - public function offsetGet($key) |
|
| 57 | - { |
|
| 58 | - if (array_key_exists($key, $this->reviews)) { |
|
| 59 | - return $this->reviews[$key]; |
|
| 60 | - } |
|
| 61 | - return property_exists($this, $key) |
|
| 62 | - ? $this->$key |
|
| 63 | - : null; |
|
| 64 | - } |
|
| 52 | + /** |
|
| 53 | + * @param mixed $key |
|
| 54 | + * @return mixed |
|
| 55 | + */ |
|
| 56 | + public function offsetGet($key) |
|
| 57 | + { |
|
| 58 | + if (array_key_exists($key, $this->reviews)) { |
|
| 59 | + return $this->reviews[$key]; |
|
| 60 | + } |
|
| 61 | + return property_exists($this, $key) |
|
| 62 | + ? $this->$key |
|
| 63 | + : null; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @return void |
|
| 68 | - */ |
|
| 69 | - public function render() |
|
| 70 | - { |
|
| 71 | - echo $this->build(); |
|
| 72 | - } |
|
| 66 | + /** |
|
| 67 | + * @return void |
|
| 68 | + */ |
|
| 69 | + public function render() |
|
| 70 | + { |
|
| 71 | + echo $this->build(); |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -24,12 +24,12 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public $reviews; |
| 26 | 26 | |
| 27 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
| 27 | + public function __construct( array $reviews, $maxPageCount, array $args ) |
|
| 28 | 28 | { |
| 29 | 29 | $this->args = $args; |
| 30 | 30 | $this->max_num_pages = $maxPageCount; |
| 31 | 31 | $this->reviews = $reviews; |
| 32 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
| 32 | + parent::__construct( $reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function __toString() |
| 39 | 39 | { |
| 40 | - return (string) $this->build(); |
|
| 40 | + return (string)$this->build(); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -45,20 +45,20 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function build() |
| 47 | 47 | { |
| 48 | - $args = glsr(SiteReviewsDefaults::class)->merge($this->args); |
|
| 49 | - return glsr(SiteReviewsPartial::class)->build($args, $this); |
|
| 48 | + $args = glsr( SiteReviewsDefaults::class )->merge( $this->args ); |
|
| 49 | + return glsr( SiteReviewsPartial::class )->build( $args, $this ); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @param mixed $key |
| 54 | 54 | * @return mixed |
| 55 | 55 | */ |
| 56 | - public function offsetGet($key) |
|
| 56 | + public function offsetGet( $key ) |
|
| 57 | 57 | { |
| 58 | - if (array_key_exists($key, $this->reviews)) { |
|
| 58 | + if( array_key_exists( $key, $this->reviews ) ) { |
|
| 59 | 59 | return $this->reviews[$key]; |
| 60 | 60 | } |
| 61 | - return property_exists($this, $key) |
|
| 61 | + return property_exists( $this, $key ) |
|
| 62 | 62 | ? $this->$key |
| 63 | 63 | : null; |
| 64 | 64 | } |
@@ -207,7 +207,8 @@ |
||
| 207 | 207 | $this->bind($id, $addon); |
| 208 | 208 | $addon->init(); |
| 209 | 209 | } |
| 210 | - } catch(\ReflectionException $e) { |
|
| 210 | + } |
|
| 211 | + catch(\ReflectionException $e) { |
|
| 211 | 212 | glsr_log()->error('Attempted to register an invalid addon.'); |
| 212 | 213 | } |
| 213 | 214 | } |
@@ -17,356 +17,356 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | final class Application extends Container |
| 19 | 19 | { |
| 20 | - const CAPABILITY = 'edit_others_posts'; |
|
| 21 | - const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
| 22 | - const ID = 'site-reviews'; |
|
| 23 | - const PAGED_QUERY_VAR = 'reviews-page'; |
|
| 24 | - const POST_TYPE = 'site-review'; |
|
| 25 | - const PREFIX = 'glsr_'; |
|
| 26 | - const TAXONOMY = 'site-review-category'; |
|
| 20 | + const CAPABILITY = 'edit_others_posts'; |
|
| 21 | + const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
| 22 | + const ID = 'site-reviews'; |
|
| 23 | + const PAGED_QUERY_VAR = 'reviews-page'; |
|
| 24 | + const POST_TYPE = 'site-review'; |
|
| 25 | + const PREFIX = 'glsr_'; |
|
| 26 | + const TAXONOMY = 'site-review-category'; |
|
| 27 | 27 | |
| 28 | - public $addons = []; |
|
| 29 | - public $defaults; |
|
| 30 | - public $deprecated = []; |
|
| 31 | - public $file; |
|
| 32 | - public $languages; |
|
| 33 | - public $mceShortcodes = []; //defined elsewhere |
|
| 34 | - public $name; |
|
| 35 | - public $postTypeColumns = []; // defined elsewhere |
|
| 36 | - public $reviewTypes; |
|
| 37 | - public $schemas = []; //defined elsewhere |
|
| 38 | - public $version; |
|
| 28 | + public $addons = []; |
|
| 29 | + public $defaults; |
|
| 30 | + public $deprecated = []; |
|
| 31 | + public $file; |
|
| 32 | + public $languages; |
|
| 33 | + public $mceShortcodes = []; //defined elsewhere |
|
| 34 | + public $name; |
|
| 35 | + public $postTypeColumns = []; // defined elsewhere |
|
| 36 | + public $reviewTypes; |
|
| 37 | + public $schemas = []; //defined elsewhere |
|
| 38 | + public $version; |
|
| 39 | 39 | |
| 40 | - public function __construct() |
|
| 41 | - { |
|
| 42 | - static::$instance = $this; |
|
| 43 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
| 44 | - $plugin = get_file_data($this->file, [ |
|
| 45 | - 'languages' => 'Domain Path', |
|
| 46 | - 'name' => 'Plugin Name', |
|
| 47 | - 'version' => 'Version', |
|
| 48 | - ], 'plugin'); |
|
| 49 | - array_walk($plugin, function ($value, $key) { |
|
| 50 | - $this->$key = $value; |
|
| 51 | - }); |
|
| 52 | - } |
|
| 40 | + public function __construct() |
|
| 41 | + { |
|
| 42 | + static::$instance = $this; |
|
| 43 | + $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
| 44 | + $plugin = get_file_data($this->file, [ |
|
| 45 | + 'languages' => 'Domain Path', |
|
| 46 | + 'name' => 'Plugin Name', |
|
| 47 | + 'version' => 'Version', |
|
| 48 | + ], 'plugin'); |
|
| 49 | + array_walk($plugin, function ($value, $key) { |
|
| 50 | + $this->$key = $value; |
|
| 51 | + }); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return void |
|
| 56 | - */ |
|
| 57 | - public function activate() |
|
| 58 | - { |
|
| 59 | - $this->scheduleCronJob(); |
|
| 60 | - add_option(static::PREFIX.'activated', true); |
|
| 61 | - } |
|
| 54 | + /** |
|
| 55 | + * @return void |
|
| 56 | + */ |
|
| 57 | + public function activate() |
|
| 58 | + { |
|
| 59 | + $this->scheduleCronJob(); |
|
| 60 | + add_option(static::PREFIX.'activated', true); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @param string $view |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function build($view, array $data = []) |
|
| 68 | - { |
|
| 69 | - ob_start(); |
|
| 70 | - $this->render($view, $data); |
|
| 71 | - return ob_get_clean(); |
|
| 72 | - } |
|
| 63 | + /** |
|
| 64 | + * @param string $view |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function build($view, array $data = []) |
|
| 68 | + { |
|
| 69 | + ob_start(); |
|
| 70 | + $this->render($view, $data); |
|
| 71 | + return ob_get_clean(); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @param string $capability |
|
| 76 | - * @return bool |
|
| 77 | - */ |
|
| 78 | - public function can($capability) |
|
| 79 | - { |
|
| 80 | - return $this->make(Role::class)->can($capability); |
|
| 81 | - } |
|
| 74 | + /** |
|
| 75 | + * @param string $capability |
|
| 76 | + * @return bool |
|
| 77 | + */ |
|
| 78 | + public function can($capability) |
|
| 79 | + { |
|
| 80 | + return $this->make(Role::class)->can($capability); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @return void |
|
| 85 | - */ |
|
| 86 | - public function catchFatalError() |
|
| 87 | - { |
|
| 88 | - $error = error_get_last(); |
|
| 89 | - if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
| 90 | - return; |
|
| 91 | - } |
|
| 92 | - glsr_log()->error($error['message']); |
|
| 93 | - } |
|
| 83 | + /** |
|
| 84 | + * @return void |
|
| 85 | + */ |
|
| 86 | + public function catchFatalError() |
|
| 87 | + { |
|
| 88 | + $error = error_get_last(); |
|
| 89 | + if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
| 90 | + return; |
|
| 91 | + } |
|
| 92 | + glsr_log()->error($error['message']); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * @param string $name |
|
| 97 | - * @return array |
|
| 98 | - */ |
|
| 99 | - public function config($name) |
|
| 100 | - { |
|
| 101 | - $configFile = $this->path('config/'.$name.'.php'); |
|
| 102 | - $config = file_exists($configFile) |
|
| 103 | - ? include $configFile |
|
| 104 | - : []; |
|
| 105 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
| 106 | - } |
|
| 95 | + /** |
|
| 96 | + * @param string $name |
|
| 97 | + * @return array |
|
| 98 | + */ |
|
| 99 | + public function config($name) |
|
| 100 | + { |
|
| 101 | + $configFile = $this->path('config/'.$name.'.php'); |
|
| 102 | + $config = file_exists($configFile) |
|
| 103 | + ? include $configFile |
|
| 104 | + : []; |
|
| 105 | + return apply_filters('site-reviews/config/'.$name, $config); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @param string $property |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function constant($property, $className = 'static') |
|
| 113 | - { |
|
| 114 | - $constant = $className.'::'.$property; |
|
| 115 | - return defined($constant) |
|
| 116 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
| 117 | - : ''; |
|
| 118 | - } |
|
| 108 | + /** |
|
| 109 | + * @param string $property |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function constant($property, $className = 'static') |
|
| 113 | + { |
|
| 114 | + $constant = $className.'::'.$property; |
|
| 115 | + return defined($constant) |
|
| 116 | + ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
| 117 | + : ''; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @return void |
|
| 122 | - */ |
|
| 123 | - public function deactivate() |
|
| 124 | - { |
|
| 125 | - $this->unscheduleCronJob(); |
|
| 126 | - } |
|
| 120 | + /** |
|
| 121 | + * @return void |
|
| 122 | + */ |
|
| 123 | + public function deactivate() |
|
| 124 | + { |
|
| 125 | + $this->unscheduleCronJob(); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * @param string $view |
|
| 130 | - * @return void|string |
|
| 131 | - */ |
|
| 132 | - public function file($view) |
|
| 133 | - { |
|
| 134 | - $view.= '.php'; |
|
| 135 | - $filePaths = []; |
|
| 136 | - if (Str::startsWith('templates/', $view)) { |
|
| 137 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
| 138 | - } |
|
| 139 | - $filePaths[] = $this->path($view); |
|
| 140 | - $filePaths[] = $this->path('views/'.$view); |
|
| 141 | - foreach ($filePaths as $file) { |
|
| 142 | - if (!file_exists($file)) { |
|
| 143 | - continue; |
|
| 144 | - } |
|
| 145 | - return $file; |
|
| 146 | - } |
|
| 147 | - } |
|
| 128 | + /** |
|
| 129 | + * @param string $view |
|
| 130 | + * @return void|string |
|
| 131 | + */ |
|
| 132 | + public function file($view) |
|
| 133 | + { |
|
| 134 | + $view.= '.php'; |
|
| 135 | + $filePaths = []; |
|
| 136 | + if (Str::startsWith('templates/', $view)) { |
|
| 137 | + $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
| 138 | + } |
|
| 139 | + $filePaths[] = $this->path($view); |
|
| 140 | + $filePaths[] = $this->path('views/'.$view); |
|
| 141 | + foreach ($filePaths as $file) { |
|
| 142 | + if (!file_exists($file)) { |
|
| 143 | + continue; |
|
| 144 | + } |
|
| 145 | + return $file; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * @return array |
|
| 151 | - */ |
|
| 152 | - public function getDefaults() |
|
| 153 | - { |
|
| 154 | - if (empty($this->defaults)) { |
|
| 155 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
| 156 | - } |
|
| 157 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
| 158 | - } |
|
| 149 | + /** |
|
| 150 | + * @return array |
|
| 151 | + */ |
|
| 152 | + public function getDefaults() |
|
| 153 | + { |
|
| 154 | + if (empty($this->defaults)) { |
|
| 155 | + $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
| 156 | + } |
|
| 157 | + return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * @param string $page |
|
| 162 | - * @param string $tab |
|
| 163 | - * @return string |
|
| 164 | - */ |
|
| 165 | - public function getPermission($page = '', $tab = 'index') |
|
| 166 | - { |
|
| 167 | - $fallback = 'edit_posts'; |
|
| 168 | - $permissions = [ |
|
| 169 | - 'addons' => 'install_plugins', |
|
| 170 | - 'documentation' => [ |
|
| 171 | - 'faq' => 'edit_others_posts', |
|
| 172 | - 'functions' => 'manage_options', |
|
| 173 | - 'hooks' => 'edit_others_posts', |
|
| 174 | - 'index' => 'edit_posts', |
|
| 175 | - 'support' => 'edit_others_posts', |
|
| 176 | - ], |
|
| 177 | - 'settings' => 'manage_options', |
|
| 178 | - 'tools' => [ |
|
| 179 | - 'console' => 'edit_others_posts', |
|
| 180 | - 'general' => 'edit_others_posts', |
|
| 181 | - 'index' => 'edit_others_posts', |
|
| 182 | - 'sync' => 'manage_options', |
|
| 183 | - 'system-info' => 'edit_others_posts', |
|
| 184 | - ] |
|
| 185 | - ]; |
|
| 186 | - $permission = Arr::get($permissions, $page, $fallback); |
|
| 187 | - if (is_array($permission)) { |
|
| 188 | - $permission = Arr::get($permission, $tab, $fallback); |
|
| 189 | - } |
|
| 190 | - return empty($permission) || !is_string($permission) |
|
| 191 | - ? $fallback |
|
| 192 | - : $permission; |
|
| 193 | - } |
|
| 160 | + /** |
|
| 161 | + * @param string $page |
|
| 162 | + * @param string $tab |
|
| 163 | + * @return string |
|
| 164 | + */ |
|
| 165 | + public function getPermission($page = '', $tab = 'index') |
|
| 166 | + { |
|
| 167 | + $fallback = 'edit_posts'; |
|
| 168 | + $permissions = [ |
|
| 169 | + 'addons' => 'install_plugins', |
|
| 170 | + 'documentation' => [ |
|
| 171 | + 'faq' => 'edit_others_posts', |
|
| 172 | + 'functions' => 'manage_options', |
|
| 173 | + 'hooks' => 'edit_others_posts', |
|
| 174 | + 'index' => 'edit_posts', |
|
| 175 | + 'support' => 'edit_others_posts', |
|
| 176 | + ], |
|
| 177 | + 'settings' => 'manage_options', |
|
| 178 | + 'tools' => [ |
|
| 179 | + 'console' => 'edit_others_posts', |
|
| 180 | + 'general' => 'edit_others_posts', |
|
| 181 | + 'index' => 'edit_others_posts', |
|
| 182 | + 'sync' => 'manage_options', |
|
| 183 | + 'system-info' => 'edit_others_posts', |
|
| 184 | + ] |
|
| 185 | + ]; |
|
| 186 | + $permission = Arr::get($permissions, $page, $fallback); |
|
| 187 | + if (is_array($permission)) { |
|
| 188 | + $permission = Arr::get($permission, $tab, $fallback); |
|
| 189 | + } |
|
| 190 | + return empty($permission) || !is_string($permission) |
|
| 191 | + ? $fallback |
|
| 192 | + : $permission; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * @param string $page |
|
| 197 | - * @param string $tab |
|
| 198 | - * @return bool |
|
| 199 | - */ |
|
| 200 | - public function hasPermission($page = '', $tab = 'index') |
|
| 201 | - { |
|
| 202 | - $isAdmin = $this->isAdmin(); |
|
| 203 | - return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab))); |
|
| 204 | - } |
|
| 195 | + /** |
|
| 196 | + * @param string $page |
|
| 197 | + * @param string $tab |
|
| 198 | + * @return bool |
|
| 199 | + */ |
|
| 200 | + public function hasPermission($page = '', $tab = 'index') |
|
| 201 | + { |
|
| 202 | + $isAdmin = $this->isAdmin(); |
|
| 203 | + return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab))); |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * @return void |
|
| 208 | - */ |
|
| 209 | - public function init() |
|
| 210 | - { |
|
| 211 | - $this->make(Actions::class)->run(); |
|
| 212 | - $this->make(Filters::class)->run(); |
|
| 213 | - } |
|
| 206 | + /** |
|
| 207 | + * @return void |
|
| 208 | + */ |
|
| 209 | + public function init() |
|
| 210 | + { |
|
| 211 | + $this->make(Actions::class)->run(); |
|
| 212 | + $this->make(Filters::class)->run(); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * @return bool |
|
| 217 | - */ |
|
| 218 | - public function isAdmin() |
|
| 219 | - { |
|
| 220 | - return is_admin() && !wp_doing_ajax(); |
|
| 221 | - } |
|
| 215 | + /** |
|
| 216 | + * @return bool |
|
| 217 | + */ |
|
| 218 | + public function isAdmin() |
|
| 219 | + { |
|
| 220 | + return is_admin() && !wp_doing_ajax(); |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * @param string $file |
|
| 225 | - * @return string |
|
| 226 | - */ |
|
| 227 | - public function path($file = '', $realpath = true) |
|
| 228 | - { |
|
| 229 | - $path = plugin_dir_path($this->file); |
|
| 230 | - if (!$realpath) { |
|
| 231 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
| 232 | - } |
|
| 233 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
| 234 | - return apply_filters('site-reviews/path', $path, $file); |
|
| 235 | - } |
|
| 223 | + /** |
|
| 224 | + * @param string $file |
|
| 225 | + * @return string |
|
| 226 | + */ |
|
| 227 | + public function path($file = '', $realpath = true) |
|
| 228 | + { |
|
| 229 | + $path = plugin_dir_path($this->file); |
|
| 230 | + if (!$realpath) { |
|
| 231 | + $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
| 232 | + } |
|
| 233 | + $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
| 234 | + return apply_filters('site-reviews/path', $path, $file); |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * @param object $addon |
|
| 239 | - * @return void |
|
| 240 | - */ |
|
| 241 | - public function register($addon) |
|
| 242 | - { |
|
| 243 | - try { |
|
| 244 | - $reflection = new \ReflectionClass($addon); |
|
| 245 | - if ($id = $reflection->getConstant('ID')) { |
|
| 246 | - $this->addons[] = $id; |
|
| 247 | - $this->bind($id, $addon); |
|
| 248 | - $addon->init(); |
|
| 249 | - } |
|
| 250 | - } catch(\ReflectionException $e) { |
|
| 251 | - glsr_log()->error('Attempted to register an invalid addon.'); |
|
| 252 | - } |
|
| 253 | - } |
|
| 237 | + /** |
|
| 238 | + * @param object $addon |
|
| 239 | + * @return void |
|
| 240 | + */ |
|
| 241 | + public function register($addon) |
|
| 242 | + { |
|
| 243 | + try { |
|
| 244 | + $reflection = new \ReflectionClass($addon); |
|
| 245 | + if ($id = $reflection->getConstant('ID')) { |
|
| 246 | + $this->addons[] = $id; |
|
| 247 | + $this->bind($id, $addon); |
|
| 248 | + $addon->init(); |
|
| 249 | + } |
|
| 250 | + } catch(\ReflectionException $e) { |
|
| 251 | + glsr_log()->error('Attempted to register an invalid addon.'); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * @return void |
|
| 257 | - */ |
|
| 258 | - public function registerAddons() |
|
| 259 | - { |
|
| 260 | - do_action('site-reviews/addon/register', $this); |
|
| 261 | - } |
|
| 255 | + /** |
|
| 256 | + * @return void |
|
| 257 | + */ |
|
| 258 | + public function registerAddons() |
|
| 259 | + { |
|
| 260 | + do_action('site-reviews/addon/register', $this); |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * @return void |
|
| 265 | - */ |
|
| 266 | - public function registerLanguages() |
|
| 267 | - { |
|
| 268 | - load_plugin_textdomain(static::ID, false, |
|
| 269 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
| 270 | - ); |
|
| 271 | - } |
|
| 263 | + /** |
|
| 264 | + * @return void |
|
| 265 | + */ |
|
| 266 | + public function registerLanguages() |
|
| 267 | + { |
|
| 268 | + load_plugin_textdomain(static::ID, false, |
|
| 269 | + trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * @return void |
|
| 275 | - */ |
|
| 276 | - public function registerReviewTypes() |
|
| 277 | - { |
|
| 278 | - $types = apply_filters('site-reviews/addon/types', []); |
|
| 279 | - $this->reviewTypes = wp_parse_args($types, [ |
|
| 280 | - 'local' => __('Local', 'site-reviews'), |
|
| 281 | - ]); |
|
| 282 | - } |
|
| 273 | + /** |
|
| 274 | + * @return void |
|
| 275 | + */ |
|
| 276 | + public function registerReviewTypes() |
|
| 277 | + { |
|
| 278 | + $types = apply_filters('site-reviews/addon/types', []); |
|
| 279 | + $this->reviewTypes = wp_parse_args($types, [ |
|
| 280 | + 'local' => __('Local', 'site-reviews'), |
|
| 281 | + ]); |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * @param string $view |
|
| 286 | - * @return void |
|
| 287 | - */ |
|
| 288 | - public function render($view, array $data = []) |
|
| 289 | - { |
|
| 290 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
| 291 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
| 292 | - if (!file_exists($file)) { |
|
| 293 | - glsr_log()->error('File not found: '.$file); |
|
| 294 | - return; |
|
| 295 | - } |
|
| 296 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
| 297 | - extract($data); |
|
| 298 | - include $file; |
|
| 299 | - } |
|
| 284 | + /** |
|
| 285 | + * @param string $view |
|
| 286 | + * @return void |
|
| 287 | + */ |
|
| 288 | + public function render($view, array $data = []) |
|
| 289 | + { |
|
| 290 | + $view = apply_filters('site-reviews/render/view', $view, $data); |
|
| 291 | + $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
| 292 | + if (!file_exists($file)) { |
|
| 293 | + glsr_log()->error('File not found: '.$file); |
|
| 294 | + return; |
|
| 295 | + } |
|
| 296 | + $data = apply_filters('site-reviews/views/data', $data, $view); |
|
| 297 | + extract($data); |
|
| 298 | + include $file; |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * @return void |
|
| 303 | - */ |
|
| 304 | - public function scheduleCronJob() |
|
| 305 | - { |
|
| 306 | - if (false === wp_next_scheduled(static::CRON_EVENT)) { |
|
| 307 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
| 308 | - } |
|
| 309 | - } |
|
| 301 | + /** |
|
| 302 | + * @return void |
|
| 303 | + */ |
|
| 304 | + public function scheduleCronJob() |
|
| 305 | + { |
|
| 306 | + if (false === wp_next_scheduled(static::CRON_EVENT)) { |
|
| 307 | + wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - /** |
|
| 312 | - * @return void |
|
| 313 | - */ |
|
| 314 | - public function setDefaults() |
|
| 315 | - { |
|
| 316 | - if (get_option(static::PREFIX.'activated')) { |
|
| 317 | - $this->make(DefaultsManager::class)->set(); |
|
| 318 | - delete_option(static::PREFIX.'activated'); |
|
| 319 | - } |
|
| 320 | - } |
|
| 311 | + /** |
|
| 312 | + * @return void |
|
| 313 | + */ |
|
| 314 | + public function setDefaults() |
|
| 315 | + { |
|
| 316 | + if (get_option(static::PREFIX.'activated')) { |
|
| 317 | + $this->make(DefaultsManager::class)->set(); |
|
| 318 | + delete_option(static::PREFIX.'activated'); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - /** |
|
| 323 | - * @param string $file |
|
| 324 | - * @return string |
|
| 325 | - */ |
|
| 326 | - public function themePath($file = '') |
|
| 327 | - { |
|
| 328 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
| 329 | - } |
|
| 322 | + /** |
|
| 323 | + * @param string $file |
|
| 324 | + * @return string |
|
| 325 | + */ |
|
| 326 | + public function themePath($file = '') |
|
| 327 | + { |
|
| 328 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - /** |
|
| 332 | - * @return void |
|
| 333 | - */ |
|
| 334 | - public function unscheduleCronJob() |
|
| 335 | - { |
|
| 336 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
| 337 | - } |
|
| 331 | + /** |
|
| 332 | + * @return void |
|
| 333 | + */ |
|
| 334 | + public function unscheduleCronJob() |
|
| 335 | + { |
|
| 336 | + wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - /** |
|
| 340 | - * @param string $path |
|
| 341 | - * @return string |
|
| 342 | - */ |
|
| 343 | - public function url($path = '') |
|
| 344 | - { |
|
| 345 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 346 | - return apply_filters('site-reviews/url', $url, $path); |
|
| 347 | - } |
|
| 339 | + /** |
|
| 340 | + * @param string $path |
|
| 341 | + * @return string |
|
| 342 | + */ |
|
| 343 | + public function url($path = '') |
|
| 344 | + { |
|
| 345 | + $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 346 | + return apply_filters('site-reviews/url', $url, $path); |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | - /** |
|
| 350 | - * @param string $versionLevel |
|
| 351 | - * @return string |
|
| 352 | - */ |
|
| 353 | - public function version($versionLevel = '') |
|
| 354 | - { |
|
| 355 | - $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
| 356 | - preg_match($pattern, $this->version, $matches); |
|
| 357 | - switch ($versionLevel) { |
|
| 358 | - case 'major': |
|
| 359 | - $version = Arr::get($matches, 1); |
|
| 360 | - break; |
|
| 361 | - case 'minor': |
|
| 362 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
| 363 | - break; |
|
| 364 | - case 'patch': |
|
| 365 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
| 366 | - break; |
|
| 367 | - } |
|
| 368 | - return empty($version) |
|
| 369 | - ? $this->version |
|
| 370 | - : $version; |
|
| 371 | - } |
|
| 349 | + /** |
|
| 350 | + * @param string $versionLevel |
|
| 351 | + * @return string |
|
| 352 | + */ |
|
| 353 | + public function version($versionLevel = '') |
|
| 354 | + { |
|
| 355 | + $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
| 356 | + preg_match($pattern, $this->version, $matches); |
|
| 357 | + switch ($versionLevel) { |
|
| 358 | + case 'major': |
|
| 359 | + $version = Arr::get($matches, 1); |
|
| 360 | + break; |
|
| 361 | + case 'minor': |
|
| 362 | + $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
| 363 | + break; |
|
| 364 | + case 'patch': |
|
| 365 | + $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
| 366 | + break; |
|
| 367 | + } |
|
| 368 | + return empty($version) |
|
| 369 | + ? $this->version |
|
| 370 | + : $version; |
|
| 371 | + } |
|
| 372 | 372 | } |
@@ -40,13 +40,13 @@ discard block |
||
| 40 | 40 | public function __construct() |
| 41 | 41 | { |
| 42 | 42 | static::$instance = $this; |
| 43 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
| 44 | - $plugin = get_file_data($this->file, [ |
|
| 43 | + $this->file = realpath( trailingslashit( dirname( __DIR__ ) ).static::ID.'.php' ); |
|
| 44 | + $plugin = get_file_data( $this->file, [ |
|
| 45 | 45 | 'languages' => 'Domain Path', |
| 46 | 46 | 'name' => 'Plugin Name', |
| 47 | 47 | 'version' => 'Version', |
| 48 | - ], 'plugin'); |
|
| 49 | - array_walk($plugin, function ($value, $key) { |
|
| 48 | + ], 'plugin' ); |
|
| 49 | + array_walk( $plugin, function( $value, $key ) { |
|
| 50 | 50 | $this->$key = $value; |
| 51 | 51 | }); |
| 52 | 52 | } |
@@ -57,17 +57,17 @@ discard block |
||
| 57 | 57 | public function activate() |
| 58 | 58 | { |
| 59 | 59 | $this->scheduleCronJob(); |
| 60 | - add_option(static::PREFIX.'activated', true); |
|
| 60 | + add_option( static::PREFIX.'activated', true ); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * @param string $view |
| 65 | 65 | * @return string |
| 66 | 66 | */ |
| 67 | - public function build($view, array $data = []) |
|
| 67 | + public function build( $view, array $data = [] ) |
|
| 68 | 68 | { |
| 69 | 69 | ob_start(); |
| 70 | - $this->render($view, $data); |
|
| 70 | + $this->render( $view, $data ); |
|
| 71 | 71 | return ob_get_clean(); |
| 72 | 72 | } |
| 73 | 73 | |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | * @param string $capability |
| 76 | 76 | * @return bool |
| 77 | 77 | */ |
| 78 | - public function can($capability) |
|
| 78 | + public function can( $capability ) |
|
| 79 | 79 | { |
| 80 | - return $this->make(Role::class)->can($capability); |
|
| 80 | + return $this->make( Role::class )->can( $capability ); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -86,34 +86,34 @@ discard block |
||
| 86 | 86 | public function catchFatalError() |
| 87 | 87 | { |
| 88 | 88 | $error = error_get_last(); |
| 89 | - if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
| 89 | + if( E_ERROR !== $error['type'] || !Str::contains( $error['message'], $this->path() ) ) { |
|
| 90 | 90 | return; |
| 91 | 91 | } |
| 92 | - glsr_log()->error($error['message']); |
|
| 92 | + glsr_log()->error( $error['message'] ); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * @param string $name |
| 97 | 97 | * @return array |
| 98 | 98 | */ |
| 99 | - public function config($name) |
|
| 99 | + public function config( $name ) |
|
| 100 | 100 | { |
| 101 | - $configFile = $this->path('config/'.$name.'.php'); |
|
| 102 | - $config = file_exists($configFile) |
|
| 101 | + $configFile = $this->path( 'config/'.$name.'.php' ); |
|
| 102 | + $config = file_exists( $configFile ) |
|
| 103 | 103 | ? include $configFile |
| 104 | 104 | : []; |
| 105 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
| 105 | + return apply_filters( 'site-reviews/config/'.$name, $config ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | 109 | * @param string $property |
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | - public function constant($property, $className = 'static') |
|
| 112 | + public function constant( $property, $className = 'static' ) |
|
| 113 | 113 | { |
| 114 | 114 | $constant = $className.'::'.$property; |
| 115 | - return defined($constant) |
|
| 116 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
| 115 | + return defined( $constant ) |
|
| 116 | + ? apply_filters( 'site-reviews/const/'.$property, constant( $constant ) ) |
|
| 117 | 117 | : ''; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -129,17 +129,17 @@ discard block |
||
| 129 | 129 | * @param string $view |
| 130 | 130 | * @return void|string |
| 131 | 131 | */ |
| 132 | - public function file($view) |
|
| 132 | + public function file( $view ) |
|
| 133 | 133 | { |
| 134 | - $view.= '.php'; |
|
| 134 | + $view .= '.php'; |
|
| 135 | 135 | $filePaths = []; |
| 136 | - if (Str::startsWith('templates/', $view)) { |
|
| 137 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
| 136 | + if( Str::startsWith( 'templates/', $view ) ) { |
|
| 137 | + $filePaths[] = $this->themePath( Str::removePrefix( 'templates/', $view ) ); |
|
| 138 | 138 | } |
| 139 | - $filePaths[] = $this->path($view); |
|
| 140 | - $filePaths[] = $this->path('views/'.$view); |
|
| 141 | - foreach ($filePaths as $file) { |
|
| 142 | - if (!file_exists($file)) { |
|
| 139 | + $filePaths[] = $this->path( $view ); |
|
| 140 | + $filePaths[] = $this->path( 'views/'.$view ); |
|
| 141 | + foreach( $filePaths as $file ) { |
|
| 142 | + if( !file_exists( $file ) ) { |
|
| 143 | 143 | continue; |
| 144 | 144 | } |
| 145 | 145 | return $file; |
@@ -151,10 +151,10 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | public function getDefaults() |
| 153 | 153 | { |
| 154 | - if (empty($this->defaults)) { |
|
| 155 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
| 154 | + if( empty($this->defaults) ) { |
|
| 155 | + $this->defaults = $this->make( DefaultsManager::class )->get(); |
|
| 156 | 156 | } |
| 157 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
| 157 | + return apply_filters( 'site-reviews/get/defaults', $this->defaults ); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * @param string $tab |
| 163 | 163 | * @return string |
| 164 | 164 | */ |
| 165 | - public function getPermission($page = '', $tab = 'index') |
|
| 165 | + public function getPermission( $page = '', $tab = 'index' ) |
|
| 166 | 166 | { |
| 167 | 167 | $fallback = 'edit_posts'; |
| 168 | 168 | $permissions = [ |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | 'system-info' => 'edit_others_posts', |
| 184 | 184 | ] |
| 185 | 185 | ]; |
| 186 | - $permission = Arr::get($permissions, $page, $fallback); |
|
| 187 | - if (is_array($permission)) { |
|
| 188 | - $permission = Arr::get($permission, $tab, $fallback); |
|
| 186 | + $permission = Arr::get( $permissions, $page, $fallback ); |
|
| 187 | + if( is_array( $permission ) ) { |
|
| 188 | + $permission = Arr::get( $permission, $tab, $fallback ); |
|
| 189 | 189 | } |
| 190 | - return empty($permission) || !is_string($permission) |
|
| 190 | + return empty($permission) || !is_string( $permission ) |
|
| 191 | 191 | ? $fallback |
| 192 | 192 | : $permission; |
| 193 | 193 | } |
@@ -197,10 +197,10 @@ discard block |
||
| 197 | 197 | * @param string $tab |
| 198 | 198 | * @return bool |
| 199 | 199 | */ |
| 200 | - public function hasPermission($page = '', $tab = 'index') |
|
| 200 | + public function hasPermission( $page = '', $tab = 'index' ) |
|
| 201 | 201 | { |
| 202 | 202 | $isAdmin = $this->isAdmin(); |
| 203 | - return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab))); |
|
| 203 | + return !$isAdmin || ($isAdmin && $this->can( $this->getPermission( $page, $tab ) )); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | public function init() |
| 210 | 210 | { |
| 211 | - $this->make(Actions::class)->run(); |
|
| 212 | - $this->make(Filters::class)->run(); |
|
| 211 | + $this->make( Actions::class )->run(); |
|
| 212 | + $this->make( Filters::class )->run(); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -224,31 +224,31 @@ discard block |
||
| 224 | 224 | * @param string $file |
| 225 | 225 | * @return string |
| 226 | 226 | */ |
| 227 | - public function path($file = '', $realpath = true) |
|
| 227 | + public function path( $file = '', $realpath = true ) |
|
| 228 | 228 | { |
| 229 | - $path = plugin_dir_path($this->file); |
|
| 230 | - if (!$realpath) { |
|
| 231 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
| 229 | + $path = plugin_dir_path( $this->file ); |
|
| 230 | + if( !$realpath ) { |
|
| 231 | + $path = trailingslashit( WP_PLUGIN_DIR ).basename( dirname( $this->file ) ); |
|
| 232 | 232 | } |
| 233 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
| 234 | - return apply_filters('site-reviews/path', $path, $file); |
|
| 233 | + $path = trailingslashit( $path ).ltrim( trim( $file ), '/' ); |
|
| 234 | + return apply_filters( 'site-reviews/path', $path, $file ); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | 238 | * @param object $addon |
| 239 | 239 | * @return void |
| 240 | 240 | */ |
| 241 | - public function register($addon) |
|
| 241 | + public function register( $addon ) |
|
| 242 | 242 | { |
| 243 | 243 | try { |
| 244 | - $reflection = new \ReflectionClass($addon); |
|
| 245 | - if ($id = $reflection->getConstant('ID')) { |
|
| 244 | + $reflection = new \ReflectionClass( $addon ); |
|
| 245 | + if( $id = $reflection->getConstant( 'ID' ) ) { |
|
| 246 | 246 | $this->addons[] = $id; |
| 247 | - $this->bind($id, $addon); |
|
| 247 | + $this->bind( $id, $addon ); |
|
| 248 | 248 | $addon->init(); |
| 249 | 249 | } |
| 250 | - } catch(\ReflectionException $e) { |
|
| 251 | - glsr_log()->error('Attempted to register an invalid addon.'); |
|
| 250 | + } catch( \ReflectionException $e ) { |
|
| 251 | + glsr_log()->error( 'Attempted to register an invalid addon.' ); |
|
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function registerAddons() |
| 259 | 259 | { |
| 260 | - do_action('site-reviews/addon/register', $this); |
|
| 260 | + do_action( 'site-reviews/addon/register', $this ); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -265,8 +265,8 @@ discard block |
||
| 265 | 265 | */ |
| 266 | 266 | public function registerLanguages() |
| 267 | 267 | { |
| 268 | - load_plugin_textdomain(static::ID, false, |
|
| 269 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
| 268 | + load_plugin_textdomain( static::ID, false, |
|
| 269 | + trailingslashit( plugin_basename( $this->path() ).'/'.$this->languages ) |
|
| 270 | 270 | ); |
| 271 | 271 | } |
| 272 | 272 | |
@@ -275,26 +275,26 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | public function registerReviewTypes() |
| 277 | 277 | { |
| 278 | - $types = apply_filters('site-reviews/addon/types', []); |
|
| 279 | - $this->reviewTypes = wp_parse_args($types, [ |
|
| 280 | - 'local' => __('Local', 'site-reviews'), |
|
| 281 | - ]); |
|
| 278 | + $types = apply_filters( 'site-reviews/addon/types', [] ); |
|
| 279 | + $this->reviewTypes = wp_parse_args( $types, [ |
|
| 280 | + 'local' => __( 'Local', 'site-reviews' ), |
|
| 281 | + ] ); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
| 285 | 285 | * @param string $view |
| 286 | 286 | * @return void |
| 287 | 287 | */ |
| 288 | - public function render($view, array $data = []) |
|
| 288 | + public function render( $view, array $data = [] ) |
|
| 289 | 289 | { |
| 290 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
| 291 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
| 292 | - if (!file_exists($file)) { |
|
| 293 | - glsr_log()->error('File not found: '.$file); |
|
| 290 | + $view = apply_filters( 'site-reviews/render/view', $view, $data ); |
|
| 291 | + $file = apply_filters( 'site-reviews/views/file', $this->file( $view ), $view, $data ); |
|
| 292 | + if( !file_exists( $file ) ) { |
|
| 293 | + glsr_log()->error( 'File not found: '.$file ); |
|
| 294 | 294 | return; |
| 295 | 295 | } |
| 296 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
| 297 | - extract($data); |
|
| 296 | + $data = apply_filters( 'site-reviews/views/data', $data, $view ); |
|
| 297 | + extract( $data ); |
|
| 298 | 298 | include $file; |
| 299 | 299 | } |
| 300 | 300 | |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | public function scheduleCronJob() |
| 305 | 305 | { |
| 306 | - if (false === wp_next_scheduled(static::CRON_EVENT)) { |
|
| 307 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
| 306 | + if( false === wp_next_scheduled( static::CRON_EVENT ) ) { |
|
| 307 | + wp_schedule_event( time(), 'twicedaily', static::CRON_EVENT ); |
|
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | |
@@ -313,9 +313,9 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | public function setDefaults() |
| 315 | 315 | { |
| 316 | - if (get_option(static::PREFIX.'activated')) { |
|
| 317 | - $this->make(DefaultsManager::class)->set(); |
|
| 318 | - delete_option(static::PREFIX.'activated'); |
|
| 316 | + if( get_option( static::PREFIX.'activated' ) ) { |
|
| 317 | + $this->make( DefaultsManager::class )->set(); |
|
| 318 | + delete_option( static::PREFIX.'activated' ); |
|
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | |
@@ -323,9 +323,9 @@ discard block |
||
| 323 | 323 | * @param string $file |
| 324 | 324 | * @return string |
| 325 | 325 | */ |
| 326 | - public function themePath($file = '') |
|
| 326 | + public function themePath( $file = '' ) |
|
| 327 | 327 | { |
| 328 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
| 328 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim( trim( $file ), '/' ); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /** |
@@ -333,36 +333,36 @@ discard block |
||
| 333 | 333 | */ |
| 334 | 334 | public function unscheduleCronJob() |
| 335 | 335 | { |
| 336 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
| 336 | + wp_unschedule_event( intval( wp_next_scheduled( static::CRON_EVENT ) ), static::CRON_EVENT ); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
| 340 | 340 | * @param string $path |
| 341 | 341 | * @return string |
| 342 | 342 | */ |
| 343 | - public function url($path = '') |
|
| 343 | + public function url( $path = '' ) |
|
| 344 | 344 | { |
| 345 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 346 | - return apply_filters('site-reviews/url', $url, $path); |
|
| 345 | + $url = esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' ) ); |
|
| 346 | + return apply_filters( 'site-reviews/url', $url, $path ); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
| 350 | 350 | * @param string $versionLevel |
| 351 | 351 | * @return string |
| 352 | 352 | */ |
| 353 | - public function version($versionLevel = '') |
|
| 353 | + public function version( $versionLevel = '' ) |
|
| 354 | 354 | { |
| 355 | 355 | $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
| 356 | - preg_match($pattern, $this->version, $matches); |
|
| 357 | - switch ($versionLevel) { |
|
| 356 | + preg_match( $pattern, $this->version, $matches ); |
|
| 357 | + switch( $versionLevel ) { |
|
| 358 | 358 | case 'major': |
| 359 | - $version = Arr::get($matches, 1); |
|
| 359 | + $version = Arr::get( $matches, 1 ); |
|
| 360 | 360 | break; |
| 361 | 361 | case 'minor': |
| 362 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
| 362 | + $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ); |
|
| 363 | 363 | break; |
| 364 | 364 | case 'patch': |
| 365 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
| 365 | + $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ).Arr::get( $matches, 3 ); |
|
| 366 | 366 | break; |
| 367 | 367 | } |
| 368 | 368 | return empty($version) |
@@ -10,52 +10,52 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Pagination implements PartialContract |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @var array |
|
| 15 | - */ |
|
| 16 | - protected $args; |
|
| 13 | + /** |
|
| 14 | + * @var array |
|
| 15 | + */ |
|
| 16 | + protected $args; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @return string |
|
| 20 | - */ |
|
| 21 | - public function build(array $args = []) |
|
| 22 | - { |
|
| 23 | - $this->args = $this->normalize($args); |
|
| 24 | - if ($this->args['total'] < 2) { |
|
| 25 | - return ''; |
|
| 26 | - } |
|
| 27 | - return glsr(Template::class)->build('templates/pagination', [ |
|
| 28 | - 'context' => [ |
|
| 29 | - 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
| 30 | - 'loader' => '<div class="glsr-loader"></div>', |
|
| 31 | - 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
| 32 | - ], |
|
| 33 | - ]); |
|
| 34 | - } |
|
| 18 | + /** |
|
| 19 | + * @return string |
|
| 20 | + */ |
|
| 21 | + public function build(array $args = []) |
|
| 22 | + { |
|
| 23 | + $this->args = $this->normalize($args); |
|
| 24 | + if ($this->args['total'] < 2) { |
|
| 25 | + return ''; |
|
| 26 | + } |
|
| 27 | + return glsr(Template::class)->build('templates/pagination', [ |
|
| 28 | + 'context' => [ |
|
| 29 | + 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
| 30 | + 'loader' => '<div class="glsr-loader"></div>', |
|
| 31 | + 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
| 32 | + ], |
|
| 33 | + ]); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - protected function buildLinks() |
|
| 40 | - { |
|
| 41 | - $args = glsr(Style::class)->paginationArgs($this->args); |
|
| 42 | - if ('array' == $args['type']) { |
|
| 43 | - $args['type'] = 'plain'; |
|
| 44 | - } |
|
| 45 | - return paginate_links($args); |
|
| 46 | - } |
|
| 36 | + /** |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + protected function buildLinks() |
|
| 40 | + { |
|
| 41 | + $args = glsr(Style::class)->paginationArgs($this->args); |
|
| 42 | + if ('array' == $args['type']) { |
|
| 43 | + $args['type'] = 'plain'; |
|
| 44 | + } |
|
| 45 | + return paginate_links($args); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @return array |
|
| 50 | - */ |
|
| 51 | - protected function normalize(array $args) |
|
| 52 | - { |
|
| 53 | - if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
| 54 | - $args['base'] = $baseUrl.'%_%'; |
|
| 55 | - } |
|
| 56 | - return wp_parse_args(array_filter($args), [ |
|
| 57 | - 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
| 58 | - 'total' => 1, |
|
| 59 | - ]); |
|
| 60 | - } |
|
| 48 | + /** |
|
| 49 | + * @return array |
|
| 50 | + */ |
|
| 51 | + protected function normalize(array $args) |
|
| 52 | + { |
|
| 53 | + if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
| 54 | + $args['base'] = $baseUrl.'%_%'; |
|
| 55 | + } |
|
| 56 | + return wp_parse_args(array_filter($args), [ |
|
| 57 | + 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
| 58 | + 'total' => 1, |
|
| 59 | + ]); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -18,19 +18,19 @@ discard block |
||
| 18 | 18 | /** |
| 19 | 19 | * @return string |
| 20 | 20 | */ |
| 21 | - public function build(array $args = []) |
|
| 21 | + public function build( array $args = [] ) |
|
| 22 | 22 | { |
| 23 | - $this->args = $this->normalize($args); |
|
| 24 | - if ($this->args['total'] < 2) { |
|
| 23 | + $this->args = $this->normalize( $args ); |
|
| 24 | + if( $this->args['total'] < 2 ) { |
|
| 25 | 25 | return ''; |
| 26 | 26 | } |
| 27 | - return glsr(Template::class)->build('templates/pagination', [ |
|
| 27 | + return glsr( Template::class )->build( 'templates/pagination', [ |
|
| 28 | 28 | 'context' => [ |
| 29 | - 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
| 29 | + 'links' => apply_filters( 'site-reviews/paginate_links', $this->buildLinks(), $this->args ), |
|
| 30 | 30 | 'loader' => '<div class="glsr-loader"></div>', |
| 31 | - 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
| 31 | + 'screen_reader_text' => __( 'Site Reviews navigation', 'site-reviews' ), |
|
| 32 | 32 | ], |
| 33 | - ]); |
|
| 33 | + ] ); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -38,24 +38,24 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | protected function buildLinks() |
| 40 | 40 | { |
| 41 | - $args = glsr(Style::class)->paginationArgs($this->args); |
|
| 42 | - if ('array' == $args['type']) { |
|
| 41 | + $args = glsr( Style::class )->paginationArgs( $this->args ); |
|
| 42 | + if( 'array' == $args['type'] ) { |
|
| 43 | 43 | $args['type'] = 'plain'; |
| 44 | 44 | } |
| 45 | - return paginate_links($args); |
|
| 45 | + return paginate_links( $args ); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * @return array |
| 50 | 50 | */ |
| 51 | - protected function normalize(array $args) |
|
| 51 | + protected function normalize( array $args ) |
|
| 52 | 52 | { |
| 53 | - if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
| 53 | + if( $baseUrl = Arr::get( $args, 'baseUrl' ) ) { |
|
| 54 | 54 | $args['base'] = $baseUrl.'%_%'; |
| 55 | 55 | } |
| 56 | - return wp_parse_args(array_filter($args), [ |
|
| 57 | - 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
| 56 | + return wp_parse_args( array_filter( $args ), [ |
|
| 57 | + 'current' => glsr( QueryBuilder::class )->getPaged(), |
|
| 58 | 58 | 'total' => 1, |
| 59 | - ]); |
|
| 59 | + ] ); |
|
| 60 | 60 | } |
| 61 | 61 | } |