@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | public static $current; |
| 18 | 18 | |
| 19 | - public $hooks = []; |
|
| 19 | + public $hooks = [ ]; |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * {@inheritdoc} |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | parent::init(); |
| 27 | 27 | |
| 28 | - add_action( 'wp_ajax_pollux/archives/featured/html', [$this, 'getFeaturedImageHtml'] ); |
|
| 29 | - add_action( 'pollux/archives/init', [$this, 'registerFeaturedImageMetaBox'] ); |
|
| 30 | - add_action( 'pollux/archives/editor', [$this, 'renderEditor'], 10, 2 ); |
|
| 31 | - add_action( 'wp_ajax_pollux/archives/featured', [$this, 'setFeaturedImage'] ); |
|
| 32 | - add_filter( 'pollux/archives/metabox/submit', [$this, 'filterSubmitMetaBox'] ); |
|
| 33 | - add_filter( 'pollux/archives/show/instructions', '__return_true' ); |
|
| 28 | + add_action( 'wp_ajax_pollux/archives/featured/html', [ $this, 'getFeaturedImageHtml' ] ); |
|
| 29 | + add_action( 'pollux/archives/init', [ $this, 'registerFeaturedImageMetaBox' ] ); |
|
| 30 | + add_action( 'pollux/archives/editor', [ $this, 'renderEditor' ], 10, 2 ); |
|
| 31 | + add_action( 'wp_ajax_pollux/archives/featured', [ $this, 'setFeaturedImage' ] ); |
|
| 32 | + add_filter( 'pollux/archives/metabox/submit', [ $this, 'filterSubmitMetaBox' ] ); |
|
| 33 | + add_filter( 'pollux/archives/show/instructions', '__return_true' ); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | public function canProceed() |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | public function filterBeforeInstructions() |
| 47 | 47 | { |
| 48 | 48 | return sprintf( '<pre class="my-sites nav-tab-active misc-pub-section">%s</pre>', |
| 49 | - array_reduce( ['title', 'content', 'featured'], function( $instructions, $id ) { |
|
| 50 | - return $instructions . $this->filterInstruction( null, ['slug' => $id], ['slug' => $this->getPostType()] ) . PHP_EOL; |
|
| 49 | + array_reduce( [ 'title', 'content', 'featured' ], function( $instructions, $id ) { |
|
| 50 | + return $instructions . $this->filterInstruction( null, [ 'slug' => $id ], [ 'slug' => $this->getPostType() ] ) . PHP_EOL; |
|
| 51 | 51 | }) |
| 52 | 52 | ); |
| 53 | 53 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function filterInstruction( $instruction, array $field, array $metabox ) |
| 61 | 61 | { |
| 62 | - return sprintf( "ArchiveMeta::%s('%s');", $metabox['slug'], $field['slug'] ); |
|
| 62 | + return sprintf( "ArchiveMeta::%s('%s');", $metabox[ 'slug' ], $field[ 'slug' ] ); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | public function filterSavedSettings( $settings ) |
| 71 | 71 | { |
| 72 | 72 | return $this->filter( 'save', array_intersect_key( |
| 73 | - array_merge( $this->getSettings(), ( new Helper )->toArray( $settings )), |
|
| 73 | + array_merge( $this->getSettings(), ( new Helper )->toArray( $settings ) ), |
|
| 74 | 74 | $this->getPostTypesWithArchive() |
| 75 | - )); |
|
| 75 | + ) ); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function filterSubmitMetaBox( array $args ) |
| 83 | 83 | { |
| 84 | - $args[1] = __( 'Save Archive', 'pollux' ); |
|
| 84 | + $args[ 1 ] = __( 'Save Archive', 'pollux' ); |
|
| 85 | 85 | return $args; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -92,10 +92,10 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function getFeaturedImageHtml() |
| 94 | 94 | { |
| 95 | - check_ajax_referer( sprintf( '%s-options', static::id() )); |
|
| 95 | + check_ajax_referer( sprintf( '%s-options', static::id() ) ); |
|
| 96 | 96 | static::$current = filter_input( INPUT_POST, 'post_type' ); |
| 97 | 97 | ob_start(); |
| 98 | - $this->renderFeaturedImageMetaBox( intval( filter_input( INPUT_POST, 'thumbnail_id' ))); |
|
| 98 | + $this->renderFeaturedImageMetaBox( intval( filter_input( INPUT_POST, 'thumbnail_id' ) ) ); |
|
| 99 | 99 | wp_send_json_success( ob_get_clean() ); |
| 100 | 100 | } |
| 101 | 101 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | public function register() |
| 118 | 118 | { |
| 119 | 119 | $screenId = ( new Helper )->getCurrentScreen()->id; |
| 120 | - if( in_array( $screenId, $this->hooks )) { |
|
| 120 | + if( in_array( $screenId, $this->hooks ) ) { |
|
| 121 | 121 | $this->hook = $screenId; |
| 122 | 122 | } |
| 123 | 123 | parent::register(); |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function registerFeaturedImageMetaBox() |
| 131 | 131 | { |
| 132 | - if( !current_user_can( 'upload_files' ))return; |
|
| 133 | - add_meta_box( 'postimagediv', __( 'Featured Image', 'pollux' ), [$this, 'renderFeaturedImageMetaBox'], null, 'side', 'low' ); |
|
| 132 | + if( !current_user_can( 'upload_files' ) )return; |
|
| 133 | + add_meta_box( 'postimagediv', __( 'Featured Image', 'pollux' ), [ $this, 'renderFeaturedImageMetaBox' ], null, 'side', 'low' ); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -140,15 +140,15 @@ discard block |
||
| 140 | 140 | public function registerPage() |
| 141 | 141 | { |
| 142 | 142 | foreach( $this->getPostTypesWithArchive() as $type => $page ) { |
| 143 | - $labels = get_post_type_labels( get_post_type_object( $type )); |
|
| 144 | - $this->hooks[$type] = call_user_func_array( 'add_submenu_page', $this->filter( 'page', [ |
|
| 143 | + $labels = get_post_type_labels( get_post_type_object( $type ) ); |
|
| 144 | + $this->hooks[ $type ] = call_user_func_array( 'add_submenu_page', $this->filter( 'page', [ |
|
| 145 | 145 | $page, |
| 146 | 146 | sprintf( _x( '%s Archive', 'post archive', 'pollux' ), $labels->singular_name ), |
| 147 | 147 | sprintf( _x( '%s Archive', 'post archive', 'pollux' ), $labels->singular_name ), |
| 148 | 148 | static::CAPABILITY, |
| 149 | 149 | sprintf( '%s_archive', $type ), |
| 150 | - [$this, 'renderPage'], |
|
| 151 | - ])); |
|
| 150 | + [ $this, 'renderPage' ], |
|
| 151 | + ] ) ); |
|
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | 'resize' => false, |
| 170 | 170 | 'wp_autoresize_on' => true, |
| 171 | 171 | ], |
| 172 | - ]); |
|
| 172 | + ] ); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -178,12 +178,12 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public function renderFeaturedImageMetaBox( $imageId = null ) |
| 180 | 180 | { |
| 181 | - if( !is_numeric( $imageId )) { |
|
| 181 | + if( !is_numeric( $imageId ) ) { |
|
| 182 | 182 | $imageId = ArchiveMeta::get( $this->getPostType(), 'featured', -1 ); |
| 183 | 183 | } |
| 184 | - $imageSize = isset( wp_get_additional_image_sizes()['post-thumbnail'] ) |
|
| 184 | + $imageSize = isset( wp_get_additional_image_sizes()[ 'post-thumbnail' ] ) |
|
| 185 | 185 | ? 'post-thumbnail' |
| 186 | - : [266, 266]; |
|
| 186 | + : [ 266, 266 ]; |
|
| 187 | 187 | $thumbnail = get_post( $imageId ) |
| 188 | 188 | ? wp_get_attachment_image( $imageId, $imageSize ) |
| 189 | 189 | : __( 'Set Featured Image', 'pollux' ); |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | 'post_type' => $this->getPostType(), |
| 196 | 196 | 'remove_image' => __( 'Remove featured image', 'pollux' ), |
| 197 | 197 | 'thumbnail' => $thumbnail, |
| 198 | - ]); |
|
| 198 | + ] ); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | public function renderPage() |
| 206 | 206 | { |
| 207 | 207 | $type = $this->getPostType(); |
| 208 | - if( empty( $type ))return; |
|
| 209 | - $labels = get_post_type_labels( get_post_type_object( $type )); |
|
| 208 | + if( empty( $type ) )return; |
|
| 209 | + $labels = get_post_type_labels( get_post_type_object( $type ) ); |
|
| 210 | 210 | $this->app->render( 'archive/index', [ |
| 211 | 211 | 'columns' => get_current_screen()->get_columns(), |
| 212 | 212 | 'content' => ArchiveMeta::get( $type, 'content', '' ), |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | 'id' => static::id(), |
| 215 | 215 | 'post_type' => $type, |
| 216 | 216 | 'title' => ArchiveMeta::get( $type, 'title', '' ), |
| 217 | - ]); |
|
| 217 | + ] ); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | protected function getDefaults() |
| 224 | 224 | { |
| 225 | - return []; |
|
| 225 | + return [ ]; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | protected function getPostType() |
| 232 | 232 | { |
| 233 | 233 | $type = array_search( $this->hook, $this->hooks ); |
| 234 | - if( !empty( $type ) && is_string( $type )) { |
|
| 234 | + if( !empty( $type ) && is_string( $type ) ) { |
|
| 235 | 235 | static::$current = $type; |
| 236 | 236 | } |
| 237 | 237 | return static::$current; |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | { |
| 245 | 245 | $types = array_map( function( $value ) { |
| 246 | 246 | return sprintf( 'edit.php?post_type=%s', $value ); |
| 247 | - }, get_post_types( ['has_archive' => 1] )); |
|
| 248 | - return array_merge( $types, ['post' => 'edit.php'] ); |
|
| 247 | + }, get_post_types( [ 'has_archive' => 1 ] ) ); |
|
| 248 | + return array_merge( $types, [ 'post' => 'edit.php' ] ); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -42,14 +42,14 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | $this->normalize( $this->app->config->{static::ID} ); |
| 44 | 44 | |
| 45 | - add_action( 'pollux/'.static::ID.'/init', [$this, 'addSubmitMetaBox'] ); |
|
| 46 | - add_action( 'current_screen', [$this, 'register'] ); |
|
| 47 | - add_action( 'admin_menu', [$this, 'registerPage'] ); |
|
| 48 | - add_action( 'admin_menu', [$this, 'registerSetting'] ); |
|
| 49 | - add_action( 'pollux/'.static::ID.'/init', [$this, 'resetPage'] ); |
|
| 50 | - add_action( 'admin_print_footer_scripts', [$this, 'renderFooterScript'] ); |
|
| 51 | - add_filter( 'pollux/'.static::ID.'/instruction', [$this, 'filterInstruction'], 10, 3 ); |
|
| 52 | - add_filter( 'pollux/'.static::ID.'/before/instructions', [$this, 'filterBeforeInstructions'] ); |
|
| 45 | + add_action( 'pollux/' . static::ID . '/init', [ $this, 'addSubmitMetaBox' ] ); |
|
| 46 | + add_action( 'current_screen', [ $this, 'register' ] ); |
|
| 47 | + add_action( 'admin_menu', [ $this, 'registerPage' ] ); |
|
| 48 | + add_action( 'admin_menu', [ $this, 'registerSetting' ] ); |
|
| 49 | + add_action( 'pollux/' . static::ID . '/init', [ $this, 'resetPage' ] ); |
|
| 50 | + add_action( 'admin_print_footer_scripts', [ $this, 'renderFooterScript' ] ); |
|
| 51 | + add_filter( 'pollux/' . static::ID . '/instruction', [ $this, 'filterInstruction' ], 10, 3 ); |
|
| 52 | + add_filter( 'pollux/' . static::ID . '/before/instructions', [ $this, 'filterBeforeInstructions' ] ); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | public function canProceed() |
@@ -67,11 +67,11 @@ discard block |
||
| 67 | 67 | call_user_func_array( 'add_meta_box', $this->filter( 'metabox/submit', [ |
| 68 | 68 | 'submitdiv', |
| 69 | 69 | __( 'Save Settings', 'pollux' ), |
| 70 | - [$this, 'renderSubmitMetaBox'], |
|
| 70 | + [ $this, 'renderSubmitMetaBox' ], |
|
| 71 | 71 | $this->hook, |
| 72 | 72 | 'side', |
| 73 | 73 | 'high', |
| 74 | - ])); |
|
| 74 | + ] ) ); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function filterInstruction( $instruction, array $field, array $metabox ) |
| 92 | 92 | { |
| 93 | - return sprintf( "SiteMeta::%s('%s');", $metabox['slug'], $field['slug'] ); |
|
| 93 | + return sprintf( "SiteMeta::%s('%s');", $metabox[ 'slug' ], $field[ 'slug' ] ); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | return $this->filter( 'save', array_merge( |
| 105 | 105 | array_intersect_key( $this->getSettings(), $settings ), |
| 106 | 106 | $settings |
| 107 | - )); |
|
| 107 | + ) ); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | public function register() |
| 126 | 126 | { |
| 127 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 128 | - if( $this->app->gatekeeper->hasDependency( self::DEPENDENCY )) { |
|
| 127 | + if( ( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 128 | + if( $this->app->gatekeeper->hasDependency( self::DEPENDENCY ) ) { |
|
| 129 | 129 | foreach( parent::register() as $metabox ) { |
| 130 | 130 | new RWMetaBox( $metabox, static::ID, $this ); |
| 131 | 131 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | add_screen_option( 'layout_columns', [ |
| 134 | 134 | 'max' => 2, |
| 135 | 135 | 'default' => 2, |
| 136 | - ]); |
|
| 136 | + ] ); |
|
| 137 | 137 | $this->action( 'init' ); |
| 138 | 138 | } |
| 139 | 139 | |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | __( 'Site Settings', 'pollux' ), |
| 149 | 149 | static::CAPABILITY, |
| 150 | 150 | static::id(), |
| 151 | - [$this, 'renderPage'], |
|
| 151 | + [ $this, 'renderPage' ], |
|
| 152 | 152 | 'dashicons-screenoptions', |
| 153 | 153 | 1313 |
| 154 | - ])); |
|
| 154 | + ] ) ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | public function registerSetting() |
| 162 | 162 | { |
| 163 | - register_setting( static::id(), static::id(), [$this, 'filterSavedSettings'] ); |
|
| 163 | + register_setting( static::id(), static::id(), [ $this, 'filterSavedSettings' ] ); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -169,12 +169,12 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | public function renderFooterScript() |
| 171 | 171 | { |
| 172 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 172 | + if( ( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 173 | 173 | $this->app->render( 'settings/script', [ |
| 174 | 174 | 'confirm' => __( 'Are you sure want to do this?', 'pollux' ), |
| 175 | 175 | 'hook' => $this->hook, |
| 176 | 176 | 'id' => static::id(), |
| 177 | - ]); |
|
| 177 | + ] ); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | 'columns' => get_current_screen()->get_columns(), |
| 188 | 188 | 'heading' => __( 'Site Settings', 'pollux' ), |
| 189 | 189 | 'id' => static::id(), |
| 190 | - ]); |
|
| 190 | + ] ); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -204,9 +204,9 @@ discard block |
||
| 204 | 204 | ]; |
| 205 | 205 | $this->app->render( 'settings/submit', [ |
| 206 | 206 | 'reset' => __( 'Reset all', 'pollux' ), |
| 207 | - 'reset_url' => esc_url( add_query_arg( $query, admin_url( $pagenow ))), |
|
| 207 | + 'reset_url' => esc_url( add_query_arg( $query, admin_url( $pagenow ) ) ), |
|
| 208 | 208 | 'submit' => get_submit_button( __( 'Save', 'pollux' ), 'primary', 'submit', false ), |
| 209 | - ]); |
|
| 209 | + ] ); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -218,15 +218,15 @@ discard block |
||
| 218 | 218 | if( filter_input( INPUT_GET, 'page' ) !== static::id() |
| 219 | 219 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
| 220 | 220 | )return; |
| 221 | - if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) { |
|
| 221 | + if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook ) ) { |
|
| 222 | 222 | update_option( static::id(), $this->getDefaults() ); |
| 223 | 223 | add_settings_error( static::id(), 'reset', __( 'Reset successful.', 'pollux' ), 'updated' ); |
| 224 | 224 | } |
| 225 | 225 | else { |
| 226 | - add_settings_error( static::id(), 'failed', __( 'Failed to reset. Please try again.', 'pollux' )); |
|
| 226 | + add_settings_error( static::id(), 'failed', __( 'Failed to reset. Please try again.', 'pollux' ) ); |
|
| 227 | 227 | } |
| 228 | 228 | set_transient( 'settings_errors', get_settings_errors(), 30 ); |
| 229 | - wp_safe_redirect( add_query_arg( 'settings-updated', 'true', wp_get_referer() )); |
|
| 229 | + wp_safe_redirect( add_query_arg( 'settings-updated', 'true', wp_get_referer() ) ); |
|
| 230 | 230 | exit; |
| 231 | 231 | } |
| 232 | 232 | |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | protected function filterArrayByKey( array $array, $key ) |
| 238 | 238 | { |
| 239 | 239 | return array_filter( $array, function( $value ) use( $key ) { |
| 240 | - return !empty( $value[$key] ); |
|
| 240 | + return !empty( $value[ $key ] ); |
|
| 241 | 241 | }); |
| 242 | 242 | } |
| 243 | 243 | |
@@ -250,11 +250,11 @@ discard block |
||
| 250 | 250 | |
| 251 | 251 | array_walk( $metaboxes, function( &$metabox ) { |
| 252 | 252 | $fields = array_map( function( $field ) { |
| 253 | - $field = wp_parse_args( $field, ['std' => ''] ); |
|
| 254 | - return [$field['slug'] => $field['std']]; |
|
| 255 | - }, $this->filterArrayByKey( $metabox['fields'], 'slug' )); |
|
| 253 | + $field = wp_parse_args( $field, [ 'std' => '' ] ); |
|
| 254 | + return [ $field[ 'slug' ] => $field[ 'std' ] ]; |
|
| 255 | + }, $this->filterArrayByKey( $metabox[ 'fields' ], 'slug' ) ); |
|
| 256 | 256 | $metabox = [ |
| 257 | - $metabox['slug'] => call_user_func_array( 'array_merge', $fields ), |
|
| 257 | + $metabox[ 'slug' ] => call_user_func_array( 'array_merge', $fields ), |
|
| 258 | 258 | ]; |
| 259 | 259 | }); |
| 260 | 260 | return call_user_func_array( 'array_merge', $metaboxes ); |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | */ |
| 273 | 273 | protected function normalizeFieldName( $name, array $data, $parentId ) |
| 274 | 274 | { |
| 275 | - return sprintf( '%s[%s][%s]', static::id(), $parentId, $data['slug'] ); |
|
| 275 | + return sprintf( '%s[%s][%s]', static::id(), $parentId, $data[ 'slug' ] ); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |