@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | { |
| 40 | 40 | if( $this->app->config->disable_config )return; |
| 41 | 41 | |
| 42 | - add_action( 'admin_menu', [$this, 'registerPage'] ); |
|
| 43 | - add_action( 'admin_menu', [$this, 'registerSetting'] ); |
|
| 44 | - add_action( 'current_screen', [$this, 'resetPage'] ); |
|
| 42 | + add_action( 'admin_menu', [ $this, 'registerPage' ] ); |
|
| 43 | + add_action( 'admin_menu', [ $this, 'registerSetting' ] ); |
|
| 44 | + add_action( 'current_screen', [ $this, 'resetPage' ] ); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | __( 'Pollux', 'pollux' ), |
| 66 | 66 | 'manage_options', |
| 67 | 67 | $this->app->id, |
| 68 | - [$this, 'renderPage'] |
|
| 68 | + [ $this, 'renderPage' ] |
|
| 69 | 69 | ); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function registerSetting() |
| 77 | 77 | { |
| 78 | - register_setting( static::id(), static::id(), [$this, 'filterSavedSettings'] ); |
|
| 78 | + register_setting( static::id(), static::id(), [ $this, 'filterSavedSettings' ] ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | 'config' => $this->app->make( ConfigManager::class ), |
| 95 | 95 | 'heading' => __( 'Pollux Settings', 'pollux' ), |
| 96 | 96 | 'id' => static::id(), |
| 97 | - 'reset_url' => esc_url( add_query_arg( $query, admin_url( 'options-general.php' ))), |
|
| 97 | + 'reset_url' => esc_url( add_query_arg( $query, admin_url( 'options-general.php' ) ) ), |
|
| 98 | 98 | 'has_meta_box' => $this->app->gatekeeper->hasDependency( 'meta-box/meta-box.php' ), |
| 99 | - ]); |
|
| 99 | + ] ); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -108,16 +108,16 @@ discard block |
||
| 108 | 108 | if( filter_input( INPUT_GET, 'page' ) !== $this->app->id |
| 109 | 109 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
| 110 | 110 | )return; |
| 111 | - if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), static::id() )) { |
|
| 111 | + if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), static::id() ) ) { |
|
| 112 | 112 | delete_option( static::id() ); |
| 113 | 113 | $this->app->make( ConfigManager::class )->compile( true ); |
| 114 | 114 | add_settings_error( static::id(), 'reset', __( 'Reset successful.', 'pollux' ), 'updated' ); |
| 115 | 115 | } |
| 116 | 116 | else { |
| 117 | - add_settings_error( static::id(), 'failed', __( 'Failed to reset. Please try again.', 'pollux' )); |
|
| 117 | + add_settings_error( static::id(), 'failed', __( 'Failed to reset. Please try again.', 'pollux' ) ); |
|
| 118 | 118 | } |
| 119 | 119 | set_transient( 'settings_errors', get_settings_errors(), 30 ); |
| 120 | - wp_safe_redirect( add_query_arg( 'settings-updated', 'true', wp_get_referer() )); |
|
| 120 | + wp_safe_redirect( add_query_arg( 'settings-updated', 'true', wp_get_referer() ) ); |
|
| 121 | 121 | exit; |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -37,7 +37,9 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function init() |
| 39 | 39 | { |
| 40 | - if( $this->app->config->disable_config )return; |
|
| 40 | + if( $this->app->config->disable_config ) { |
|
| 41 | + return; |
|
| 42 | + } |
|
| 41 | 43 | |
| 42 | 44 | add_action( 'admin_menu', [$this, 'registerPage'] ); |
| 43 | 45 | add_action( 'admin_menu', [$this, 'registerSetting'] ); |
@@ -107,7 +109,9 @@ discard block |
||
| 107 | 109 | { |
| 108 | 110 | if( filter_input( INPUT_GET, 'page' ) !== $this->app->id |
| 109 | 111 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
| 110 | - )return; |
|
| 112 | + ) { |
|
| 113 | + return; |
|
| 114 | + } |
|
| 111 | 115 | if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), static::id() )) { |
| 112 | 116 | delete_option( static::id() ); |
| 113 | 117 | $this->app->make( ConfigManager::class )->compile( true ); |
@@ -42,13 +42,13 @@ discard block |
||
| 42 | 42 | $yamlFile = $this->getYamlFile(); |
| 43 | 43 | $yaml = $this->normalizeYamlValues( $this->normalize( |
| 44 | 44 | $this->parseYaml( file_get_contents( $yamlFile ), $yamlFile ) |
| 45 | - )); |
|
| 46 | - if( !$yaml['disable_config'] ) { |
|
| 47 | - $config = array_filter( (array) get_option( Config::id(), [] )); |
|
| 45 | + ) ); |
|
| 46 | + if( !$yaml[ 'disable_config' ] ) { |
|
| 47 | + $config = array_filter( (array) get_option( Config::id(), [ ] ) ); |
|
| 48 | 48 | } |
| 49 | 49 | return empty( $config ) |
| 50 | - ? $this->setTimestamp( $yaml, filemtime( $yamlFile )) |
|
| 51 | - : $this->normalizeYamlValues( $this->normalize( $config )); |
|
| 50 | + ? $this->setTimestamp( $yaml, filemtime( $yamlFile ) ) |
|
| 51 | + : $this->normalizeYamlValues( $this->normalize( $config ) ); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -58,15 +58,15 @@ discard block |
||
| 58 | 58 | public function compile( $force = false ) |
| 59 | 59 | { |
| 60 | 60 | $configFile = $this->getCompileDestination(); |
| 61 | - if( $force || $this->shouldCompile( $configFile )) { |
|
| 61 | + if( $force || $this->shouldCompile( $configFile ) ) { |
|
| 62 | 62 | $config = $this->normalizeArray( $this->options ); |
| 63 | 63 | if( $this->parseError ) { |
| 64 | 64 | return (object) $config; |
| 65 | 65 | } |
| 66 | 66 | file_put_contents( $configFile, sprintf( '<?php // DO NOT MODIFY THIS FILE DIRECTLY!%sreturn (object) %s;', |
| 67 | 67 | PHP_EOL, |
| 68 | - $this->parseRawStrings( var_export( $this->setTimestamp( $config ), true )) |
|
| 69 | - )); |
|
| 68 | + $this->parseRawStrings( var_export( $this->setTimestamp( $config ), true ) ) |
|
| 69 | + ) ); |
|
| 70 | 70 | } |
| 71 | 71 | return include $configFile; |
| 72 | 72 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | public function convertArrayToYaml( array $array ) |
| 78 | 78 | { |
| 79 | 79 | return !empty( $array ) |
| 80 | - ? trim( $this->parseRawStrings( $this->dumpYaml( $array ))) |
|
| 80 | + ? trim( $this->parseRawStrings( $this->dumpYaml( $array ) ) ) |
|
| 81 | 81 | : ''; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -104,11 +104,11 @@ discard block |
||
| 104 | 104 | trailingslashit( trailingslashit( $theme->theme_root ) . $theme->template ), |
| 105 | 105 | trailingslashit( WP_CONTENT_DIR ), |
| 106 | 106 | trailingslashit( ABSPATH ), |
| 107 | - trailingslashit( dirname( ABSPATH )), |
|
| 108 | - trailingslashit( dirname( dirname( ABSPATH ))), |
|
| 109 | - ]); |
|
| 107 | + trailingslashit( dirname( ABSPATH ) ), |
|
| 108 | + trailingslashit( dirname( dirname( ABSPATH ) ) ), |
|
| 109 | + ] ); |
|
| 110 | 110 | foreach( (array) $configLocations as $location ) { |
| 111 | - if( !file_exists( $location . $configYaml ))continue; |
|
| 111 | + if( !file_exists( $location . $configYaml ) )continue; |
|
| 112 | 112 | return $location . $configYaml; |
| 113 | 113 | } |
| 114 | 114 | return $this->app->path( 'defaults.yml' ); |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | public function normalizeArray( array $array ) |
| 121 | 121 | { |
| 122 | 122 | array_walk( $array, function( &$value, $key ) { |
| 123 | - if( !is_numeric( $value ) && is_string( $value )) { |
|
| 123 | + if( !is_numeric( $value ) && is_string( $value ) ) { |
|
| 124 | 124 | $value = $this->parseYaml( $value, $key ); |
| 125 | 125 | if( $this->parseError == $key ) { |
| 126 | - $value = []; |
|
| 126 | + $value = [ ]; |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | }); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | public function setTimestamp( array $config, $timestamp = null ) |
| 149 | 149 | { |
| 150 | 150 | $timestamp || $timestamp = time(); |
| 151 | - $config['updated'] = $timestamp; |
|
| 151 | + $config[ 'updated' ] = $timestamp; |
|
| 152 | 152 | return $config; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | return wp_parse_args( |
| 174 | 174 | $config, |
| 175 | 175 | $this->parseYaml( |
| 176 | - file_get_contents( $this->app->path( 'defaults.yml' )), |
|
| 176 | + file_get_contents( $this->app->path( 'defaults.yml' ) ), |
|
| 177 | 177 | $this->app->path( 'defaults.yml' ) |
| 178 | 178 | ) |
| 179 | 179 | ); |
@@ -187,13 +187,13 @@ discard block |
||
| 187 | 187 | protected function parseRawStrings( $configString ) |
| 188 | 188 | { |
| 189 | 189 | $strings = apply_filters( 'pollux/config/raw_strings', static::RAW_STRINGS ); |
| 190 | - if( empty( $strings )) { |
|
| 190 | + if( empty( $strings ) ) { |
|
| 191 | 191 | return $configString; |
| 192 | 192 | } |
| 193 | 193 | $pattern = '/(\')((' . implode( '|', $strings ) . ')\(?.+\))(\')/'; |
| 194 | 194 | return stripslashes( |
| 195 | 195 | preg_replace_callback( $pattern, function( $matches ) { |
| 196 | - return str_replace( "''", "'", $matches[2] ); |
|
| 196 | + return str_replace( "''", "'", $matches[ 2 ] ); |
|
| 197 | 197 | }, $configString ) |
| 198 | 198 | ); |
| 199 | 199 | } |
@@ -212,13 +212,13 @@ discard block |
||
| 212 | 212 | if( $file ) { |
| 213 | 213 | $file = sprintf( '<code>%s</code>', $file ); |
| 214 | 214 | } |
| 215 | - $this->app->make( 'Notice' )->addError([ |
|
| 215 | + $this->app->make( 'Notice' )->addError( [ |
|
| 216 | 216 | sprintf( '<strong>Pollux Error:</strong> Unable to parse config at line %s (near "%s").', |
| 217 | 217 | $e->getParsedLine(), |
| 218 | 218 | $e->getSnippet() |
| 219 | 219 | ), |
| 220 | 220 | $file |
| 221 | - ]); |
|
| 221 | + ] ); |
|
| 222 | 222 | return $value; |
| 223 | 223 | } |
| 224 | 224 | } |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | protected function shouldCompile( $configFile ) |
| 231 | 231 | { |
| 232 | - if( !file_exists( $configFile )) { |
|
| 232 | + if( !file_exists( $configFile ) ) { |
|
| 233 | 233 | return true; |
| 234 | 234 | } |
| 235 | 235 | $config = include $configFile; |