@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | CONST ID = 'archives'; |
| 16 | 16 | |
| 17 | - public $hooks = []; |
|
| 17 | + public $hooks = [ ]; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * {@inheritdoc} |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | { |
| 24 | 24 | parent::init(); |
| 25 | 25 | |
| 26 | - add_action( 'pollux/archives/init', [$this, 'registerFeaturedImageMetaBox'] ); |
|
| 27 | - add_action( 'pollux/archives/editor', [$this, 'renderEditor'], 10, 2 ); |
|
| 28 | - add_filter( 'pollux/archives/metabox/submit', [$this, 'filterSubmitMetaBox'] ); |
|
| 26 | + add_action( 'pollux/archives/init', [ $this, 'registerFeaturedImageMetaBox' ] ); |
|
| 27 | + add_action( 'pollux/archives/editor', [ $this, 'renderEditor' ], 10, 2 ); |
|
| 28 | + add_filter( 'pollux/archives/metabox/submit', [ $this, 'filterSubmitMetaBox' ] ); |
|
| 29 | 29 | add_filter( 'pollux/archives/show/instructions', '__return_true' ); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -36,15 +36,15 @@ discard block |
||
| 36 | 36 | public function addPage() |
| 37 | 37 | { |
| 38 | 38 | foreach( $this->getPostTypesWithArchive() as $type => $page ) { |
| 39 | - $labels = get_post_type_labels( get_post_type_object( $type )); |
|
| 40 | - $this->hooks[$type] = call_user_func_array( 'add_submenu_page', $this->filter( 'page', [ |
|
| 39 | + $labels = get_post_type_labels( get_post_type_object( $type ) ); |
|
| 40 | + $this->hooks[ $type ] = call_user_func_array( 'add_submenu_page', $this->filter( 'page', [ |
|
| 41 | 41 | $page, |
| 42 | 42 | sprintf( _x( '%s Archive', 'post archive', 'pollux' ), $labels->singular_name ), |
| 43 | 43 | __( 'Archive', 'pollux' ), |
| 44 | 44 | 'edit_theme_options', |
| 45 | 45 | sprintf( '%s_archive', $type ), |
| 46 | - [$this, 'renderPage'], |
|
| 47 | - ])); |
|
| 46 | + [ $this, 'renderPage' ], |
|
| 47 | + ] ) ); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | public function filterBeforeInstructions() |
| 56 | 56 | { |
| 57 | 57 | return sprintf( '<pre class="my-sites nav-tab-active misc-pub-section">%s</pre>', |
| 58 | - array_reduce( ['title', 'content', 'featured'], function( $instructions, $id ) { |
|
| 59 | - return $instructions . $this->filterInstruction( null, ['slug' => $id], ['slug' => $this->getPostType()] ) . PHP_EOL; |
|
| 58 | + array_reduce( [ 'title', 'content', 'featured' ], function( $instructions, $id ) { |
|
| 59 | + return $instructions . $this->filterInstruction( null, [ 'slug' => $id ], [ 'slug' => $this->getPostType() ] ) . PHP_EOL; |
|
| 60 | 60 | }) |
| 61 | 61 | ); |
| 62 | 62 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function filterInstruction( $instruction, array $field, array $metabox ) |
| 70 | 70 | { |
| 71 | - return sprintf( "ArchiveMeta::%s('%s');", $metabox['slug'], $field['slug'] ); |
|
| 71 | + return sprintf( "ArchiveMeta::%s('%s');", $metabox[ 'slug' ], $field[ 'slug' ] ); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | public function filterSubmitMetaBox( array $args ) |
| 79 | 79 | { |
| 80 | - $args[1] = __( 'Save Archive', 'pollux' ); |
|
| 80 | + $args[ 1 ] = __( 'Save Archive', 'pollux' ); |
|
| 81 | 81 | return $args; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | public function register() |
| 89 | 89 | { |
| 90 | 90 | $screenId = ( new Helper )->getCurrentScreen()->id; |
| 91 | - if( in_array( $screenId, $this->hooks )) { |
|
| 91 | + if( in_array( $screenId, $this->hooks ) ) { |
|
| 92 | 92 | $this->hook = $screenId; |
| 93 | 93 | } |
| 94 | 94 | parent::register(); |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public function registerFeaturedImageMetaBox() |
| 102 | 102 | { |
| 103 | - if( !current_user_can( 'upload_files' ))return; |
|
| 104 | - add_meta_box( 'postimagediv', __( 'Featured Image', 'pollux' ), [$this, 'renderFeaturedImageMetaBox'], null, 'side', 'low' ); |
|
| 103 | + if( !current_user_can( 'upload_files' ) )return; |
|
| 104 | + add_meta_box( 'postimagediv', __( 'Featured Image', 'pollux' ), [ $this, 'renderFeaturedImageMetaBox' ], null, 'side', 'low' ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | 'resize' => false, |
| 122 | 122 | 'wp_autoresize_on' => true, |
| 123 | 123 | ], |
| 124 | - ]); |
|
| 124 | + ] ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -131,9 +131,9 @@ discard block |
||
| 131 | 131 | public function renderFeaturedImageMetaBox() |
| 132 | 132 | { |
| 133 | 133 | $imageId = ArchiveMeta::get( 'featured', -1, $this->getPostType() ); |
| 134 | - $imageSize = isset( wp_get_additional_image_sizes()['post-thumbnail'] ) |
|
| 134 | + $imageSize = isset( wp_get_additional_image_sizes()[ 'post-thumbnail' ] ) |
|
| 135 | 135 | ? 'post-thumbnail' |
| 136 | - : [266, 266]; |
|
| 136 | + : [ 266, 266 ]; |
|
| 137 | 137 | $thumbnail = get_post( $imageId ) |
| 138 | 138 | ? wp_get_attachment_image( $imageId, $imageSize ) |
| 139 | 139 | : __( 'Set Featured Image', 'pollux' ); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | 'remove_image' => __( 'Remove featured image', 'pollux' ), |
| 147 | 147 | 'thickbox_url' => '', |
| 148 | 148 | 'thumbnail' => $thumbnail, |
| 149 | - ]); |
|
| 149 | + ] ); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | public function renderPage() |
| 157 | 157 | { |
| 158 | 158 | $type = $this->getPostType(); |
| 159 | - if( empty( $type ))return; |
|
| 160 | - $labels = get_post_type_labels( get_post_type_object( $type )); |
|
| 159 | + if( empty( $type ) )return; |
|
| 160 | + $labels = get_post_type_labels( get_post_type_object( $type ) ); |
|
| 161 | 161 | $this->render( 'archive/index', [ |
| 162 | 162 | 'columns' => get_current_screen()->get_columns(), |
| 163 | 163 | 'content' => ArchiveMeta::get( 'content', '', $type ), |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | 'id' => static::id(), |
| 166 | 166 | 'post_type' => $type, |
| 167 | 167 | 'title' => ArchiveMeta::get( 'title', '', $type ), |
| 168 | - ]); |
|
| 168 | + ] ); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | protected function getDefaults() |
| 175 | 175 | { |
| 176 | - return []; |
|
| 176 | + return [ ]; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | { |
| 195 | 195 | $types = array_map( function( $value ) { |
| 196 | 196 | return sprintf( 'edit.php?post_type=%s', $value ); |
| 197 | - }, get_post_types( ['has_archive' => 1] )); |
|
| 198 | - return array_merge( $types, ['post' => 'edit.php'] ); |
|
| 197 | + }, get_post_types( [ 'has_archive' => 1 ] ) ); |
|
| 198 | + return array_merge( $types, [ 'post' => 'edit.php' ] ); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -44,16 +44,16 @@ discard block |
||
| 44 | 44 | // @todo: run GateKeeper to check dependencies and capability (make sure it it run on the correct hook!) |
| 45 | 45 | // if( !is_plugin_active( 'meta-box/meta-box.php' ))return; |
| 46 | 46 | |
| 47 | - $this->normalize( $this->app->config[static::ID] ); |
|
| 47 | + $this->normalize( $this->app->config[ static::ID ] ); |
|
| 48 | 48 | |
| 49 | - add_action( 'admin_menu', [$this, 'addPage'] ); |
|
| 50 | - add_action( 'pollux/'.static::ID.'/init', [$this, 'addSubmitMetaBox'] ); |
|
| 51 | - add_action( 'current_screen', [$this, 'register'] ); |
|
| 52 | - add_action( 'admin_menu', [$this, 'registerSetting'] ); |
|
| 53 | - add_action( 'pollux/'.static::ID.'/init', [$this, 'reset'] ); |
|
| 54 | - add_action( 'admin_print_footer_scripts', [$this, 'renderFooterScript'] ); |
|
| 55 | - add_filter( 'pollux/'.static::ID.'/instruction', [$this, 'filterInstruction'], 10, 3 ); |
|
| 56 | - add_filter( 'pollux/'.static::ID.'/before/instructions', [$this, 'filterBeforeInstructions'] ); |
|
| 49 | + add_action( 'admin_menu', [ $this, 'addPage' ] ); |
|
| 50 | + add_action( 'pollux/' . static::ID . '/init', [ $this, 'addSubmitMetaBox' ] ); |
|
| 51 | + add_action( 'current_screen', [ $this, 'register' ] ); |
|
| 52 | + add_action( 'admin_menu', [ $this, 'registerSetting' ] ); |
|
| 53 | + add_action( 'pollux/' . static::ID . '/init', [ $this, 'reset' ] ); |
|
| 54 | + add_action( 'admin_print_footer_scripts', [ $this, 'renderFooterScript' ] ); |
|
| 55 | + add_filter( 'pollux/' . static::ID . '/instruction', [ $this, 'filterInstruction' ], 10, 3 ); |
|
| 56 | + add_filter( 'pollux/' . static::ID . '/before/instructions', [ $this, 'filterBeforeInstructions' ] ); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | public function action() |
| 63 | 63 | { |
| 64 | 64 | $args = func_get_args(); |
| 65 | - $hook = sprintf( 'pollux/%s/%s', static::ID, array_shift( $args )); |
|
| 65 | + $hook = sprintf( 'pollux/%s/%s', static::ID, array_shift( $args ) ); |
|
| 66 | 66 | return do_action_ref_array( $hook, $args ); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | __( 'Site Settings', 'pollux' ), |
| 78 | 78 | 'edit_theme_options', |
| 79 | 79 | static::id(), |
| 80 | - [$this, 'renderPage'], |
|
| 80 | + [ $this, 'renderPage' ], |
|
| 81 | 81 | 'dashicons-screenoptions', |
| 82 | 82 | 1313 |
| 83 | - ])); |
|
| 83 | + ] ) ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | call_user_func_array( 'add_meta_box', $this->filter( 'metabox/submit', [ |
| 93 | 93 | 'submitdiv', |
| 94 | 94 | __( 'Save Settings', 'pollux' ), |
| 95 | - [$this, 'renderSubmitMetaBox'], |
|
| 95 | + [ $this, 'renderSubmitMetaBox' ], |
|
| 96 | 96 | $this->hook, |
| 97 | 97 | 'side', |
| 98 | 98 | 'high', |
| 99 | - ])); |
|
| 99 | + ] ) ); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | public function filter() |
| 106 | 106 | { |
| 107 | 107 | $args = func_get_args(); |
| 108 | - $hook = sprintf( 'pollux/%s/%s', static::ID, array_shift( $args )); |
|
| 108 | + $hook = sprintf( 'pollux/%s/%s', static::ID, array_shift( $args ) ); |
|
| 109 | 109 | return apply_filters_ref_array( $hook, $args ); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function filterInstruction( $instruction, array $field, array $metabox ) |
| 127 | 127 | { |
| 128 | - return sprintf( "SiteMeta::%s('%s');", $metabox['slug'], $field['slug'] ); |
|
| 128 | + return sprintf( "SiteMeta::%s('%s');", $metabox[ 'slug' ], $field[ 'slug' ] ); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | public function filterSavedSettings( $settings ) |
| 137 | 137 | { |
| 138 | - if( is_null( $settings )) { |
|
| 139 | - $settings = []; |
|
| 138 | + if( is_null( $settings ) ) { |
|
| 139 | + $settings = [ ]; |
|
| 140 | 140 | } |
| 141 | - return $this->filter( 'save', array_merge( $settings, $this->getSettings() )); |
|
| 141 | + return $this->filter( 'save', array_merge( $settings, $this->getSettings() ) ); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -147,14 +147,14 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | public function register() |
| 149 | 149 | { |
| 150 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 150 | + if( ( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 151 | 151 | foreach( parent::register() as $metabox ) { |
| 152 | 152 | new RWMetaBox( $metabox, static::ID, $this->hook ); |
| 153 | 153 | } |
| 154 | 154 | add_screen_option( 'layout_columns', [ |
| 155 | 155 | 'max' => 2, |
| 156 | 156 | 'default' => 2, |
| 157 | - ]); |
|
| 157 | + ] ); |
|
| 158 | 158 | $this->action( 'init' ); |
| 159 | 159 | } |
| 160 | 160 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | public function registerSetting() |
| 166 | 166 | { |
| 167 | - register_setting( static::id(), static::id(), [$this, 'filterSavedSettings'] ); |
|
| 167 | + register_setting( static::id(), static::id(), [ $this, 'filterSavedSettings' ] ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -173,12 +173,12 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | public function renderFooterScript() |
| 175 | 175 | { |
| 176 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 176 | + if( ( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 177 | 177 | $this->render( 'settings/script', [ |
| 178 | 178 | 'confirm' => __( 'Are you sure want to do this?', 'pollux' ), |
| 179 | 179 | 'hook' => $this->hook, |
| 180 | 180 | 'id' => static::id(), |
| 181 | - ]); |
|
| 181 | + ] ); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | 'columns' => get_current_screen()->get_columns(), |
| 192 | 192 | 'heading' => __( 'Site Settings', 'pollux' ), |
| 193 | 193 | 'id' => static::id(), |
| 194 | - ]); |
|
| 194 | + ] ); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -208,9 +208,9 @@ discard block |
||
| 208 | 208 | ]; |
| 209 | 209 | $this->render( 'settings/submit', [ |
| 210 | 210 | 'reset' => __( 'Reset all', 'pollux' ), |
| 211 | - 'reset_url' => esc_url( add_query_arg( $query, admin_url( $pagenow ))), |
|
| 211 | + 'reset_url' => esc_url( add_query_arg( $query, admin_url( $pagenow ) ) ), |
|
| 212 | 212 | 'submit' => get_submit_button( __( 'Save', 'pollux' ), 'primary', 'submit', false ), |
| 213 | - ]); |
|
| 213 | + ] ); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -222,15 +222,15 @@ discard block |
||
| 222 | 222 | if( filter_input( INPUT_GET, 'page' ) !== static::id() |
| 223 | 223 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
| 224 | 224 | )return; |
| 225 | - if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) { |
|
| 225 | + if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook ) ) { |
|
| 226 | 226 | update_option( static::id(), $this->getDefaults() ); |
| 227 | 227 | add_settings_error( static::id(), 'reset', __( 'Reset successful.', 'pollux' ), 'updated' ); |
| 228 | 228 | } |
| 229 | 229 | else { |
| 230 | - add_settings_error( static::id(), 'failed', __( 'Failed to reset. Please try again.', 'pollux' )); |
|
| 230 | + add_settings_error( static::id(), 'failed', __( 'Failed to reset. Please try again.', 'pollux' ) ); |
|
| 231 | 231 | } |
| 232 | 232 | set_transient( 'settings_errors', get_settings_errors(), 30 ); |
| 233 | - wp_safe_redirect( add_query_arg( 'settings-updated', 'true', wp_get_referer() )); |
|
| 233 | + wp_safe_redirect( add_query_arg( 'settings-updated', 'true', wp_get_referer() ) ); |
|
| 234 | 234 | exit; |
| 235 | 235 | } |
| 236 | 236 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | protected function filterArrayByKey( array $array, $key ) |
| 242 | 242 | { |
| 243 | 243 | return array_filter( $array, function( $value ) use( $key ) { |
| 244 | - return !empty( $value[$key] ); |
|
| 244 | + return !empty( $value[ $key ] ); |
|
| 245 | 245 | }); |
| 246 | 246 | } |
| 247 | 247 | |
@@ -254,11 +254,11 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | array_walk( $metaboxes, function( &$metabox ) { |
| 256 | 256 | $fields = array_map( function( $field ) { |
| 257 | - $field = wp_parse_args( $field, ['std' => ''] ); |
|
| 258 | - return [$field['slug'] => $field['std']]; |
|
| 259 | - }, $this->filterArrayByKey( $metabox['fields'], 'slug' )); |
|
| 257 | + $field = wp_parse_args( $field, [ 'std' => '' ] ); |
|
| 258 | + return [ $field[ 'slug' ] => $field[ 'std' ] ]; |
|
| 259 | + }, $this->filterArrayByKey( $metabox[ 'fields' ], 'slug' ) ); |
|
| 260 | 260 | $metabox = [ |
| 261 | - $metabox['slug'] => call_user_func_array( 'array_merge', $fields ), |
|
| 261 | + $metabox[ 'slug' ] => call_user_func_array( 'array_merge', $fields ), |
|
| 262 | 262 | ]; |
| 263 | 263 | }); |
| 264 | 264 | return call_user_func_array( 'array_merge', $metaboxes ); |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | */ |
| 285 | 285 | protected function normalizeFieldName( $name, array $data, $parentId ) |
| 286 | 286 | { |
| 287 | - return sprintf( '%s[%s][%s]', static::id(), $parentId, $data['slug'] ); |
|
| 287 | + return sprintf( '%s[%s][%s]', static::id(), $parentId, $data[ 'slug' ] ); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -21,12 +21,12 @@ discard block |
||
| 21 | 21 | $this->pollux_hook = $hook; |
| 22 | 22 | $this->pollux_id = $id; |
| 23 | 23 | |
| 24 | - remove_action( 'add_meta_boxes', [$this, 'add_meta_boxes'] ); |
|
| 25 | - remove_action( 'save_post_post', [$this, 'save_post'] ); |
|
| 24 | + remove_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] ); |
|
| 25 | + remove_action( 'save_post_post', [ $this, 'save_post' ] ); |
|
| 26 | 26 | |
| 27 | - add_action( 'pollux/archives/init', [$this, 'add_meta_boxes'] ); |
|
| 28 | - add_action( 'pollux/settings/init', [$this, 'add_meta_boxes'] ); |
|
| 29 | - add_filter( 'rwmb_field_meta', [$this, '_get_field_meta'], 10, 3 ); |
|
| 27 | + add_action( 'pollux/archives/init', [ $this, 'add_meta_boxes' ] ); |
|
| 28 | + add_action( 'pollux/settings/init', [ $this, 'add_meta_boxes' ] ); |
|
| 29 | + add_filter( 'rwmb_field_meta', [ $this, '_get_field_meta' ], 10, 3 ); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -37,13 +37,13 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function _get_field_meta( $meta, array $field, $saved ) |
| 39 | 39 | { |
| 40 | - if( !$this->is_edit_screen() || !empty(( new Helper )->toArray( $meta )) || empty( $field['slug'] )) { |
|
| 40 | + if( !$this->is_edit_screen() || !empty( ( new Helper )->toArray( $meta ) ) || empty( $field[ 'slug' ] ) ) { |
|
| 41 | 41 | return $meta; |
| 42 | 42 | } |
| 43 | - $meta = call_user_func( [RWMB_Field::get_class_name( $field ), 'esc_meta'], ( $saved |
|
| 44 | - ? SiteMeta::get( $this->meta_box['slug'], $field['slug'], $meta ) |
|
| 45 | - : $field['std'] |
|
| 46 | - )); |
|
| 43 | + $meta = call_user_func( [ RWMB_Field::get_class_name( $field ), 'esc_meta' ], ( $saved |
|
| 44 | + ? SiteMeta::get( $this->meta_box[ 'slug' ], $field[ 'slug' ], $meta ) |
|
| 45 | + : $field[ 'std' ] |
|
| 46 | + ) ); |
|
| 47 | 47 | return $this->_normalize_field_meta( $meta, $field ); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function _normalize_field_meta( $meta, array $field ) |
| 55 | 55 | { |
| 56 | - if( !empty( $meta ) && is_array( $meta )) { |
|
| 56 | + if( !empty( $meta ) && is_array( $meta ) ) { |
|
| 57 | 57 | return $meta; |
| 58 | 58 | } |
| 59 | - if( $field['clone'] ) { |
|
| 60 | - return ['']; |
|
| 59 | + if( $field[ 'clone' ] ) { |
|
| 60 | + return [ '' ]; |
|
| 61 | 61 | } |
| 62 | - if( $field['multiple'] ) { |
|
| 63 | - return []; |
|
| 62 | + if( $field[ 'multiple' ] ) { |
|
| 63 | + return [ ]; |
|
| 64 | 64 | } |
| 65 | 65 | return $meta; |
| 66 | 66 | } |
@@ -73,12 +73,12 @@ discard block |
||
| 73 | 73 | public function add_meta_boxes() |
| 74 | 74 | { |
| 75 | 75 | add_meta_box( |
| 76 | - $this->meta_box['id'], |
|
| 77 | - $this->meta_box['title'], |
|
| 78 | - [$this, 'show'], |
|
| 76 | + $this->meta_box[ 'id' ], |
|
| 77 | + $this->meta_box[ 'title' ], |
|
| 78 | + [ $this, 'show' ], |
|
| 79 | 79 | null, |
| 80 | - $this->meta_box['context'], |
|
| 81 | - $this->meta_box['priority'] |
|
| 80 | + $this->meta_box[ 'context' ], |
|
| 81 | + $this->meta_box[ 'priority' ] |
|
| 82 | 82 | ); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | public function is_saved() |
| 97 | 97 | { |
| 98 | 98 | foreach( array_column( $this->fields, 'slug' ) as $field ) { |
| 99 | - if( !is_null( SiteMeta::get( $this->meta_box['slug'], $field, null ))) { |
|
| 99 | + if( !is_null( SiteMeta::get( $this->meta_box[ 'slug' ], $field, null ) ) ) { |
|
| 100 | 100 | return true; |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public static function normalize( $metabox ) |
| 111 | 111 | { |
| 112 | - unset( $metabox['post_types'] ); |
|
| 113 | - return wp_parse_args( $metabox, ['slug' => ''] ); |
|
| 112 | + unset( $metabox[ 'post_types' ] ); |
|
| 113 | + return wp_parse_args( $metabox, [ 'slug' => '' ] ); |
|
| 114 | 114 | } |
| 115 | 115 | } |
@@ -16,19 +16,19 @@ discard block |
||
| 16 | 16 | * @param string $metaKey |
| 17 | 17 | * @return mixed |
| 18 | 18 | */ |
| 19 | - public function get( $metaKey, array $args = [] ) |
|
| 19 | + public function get( $metaKey, array $args = [ ] ) |
|
| 20 | 20 | { |
| 21 | - if( empty( $metaKey ))return; |
|
| 21 | + if( empty( $metaKey ) )return; |
|
| 22 | 22 | |
| 23 | 23 | $args = $this->normalize( $args ); |
| 24 | - $metaKey = $this->buildMetaKey( $metaKey, $args['prefix'] ); |
|
| 25 | - $metaValue = get_post_meta( $args['id'], $metaKey, $args['single'] ); |
|
| 24 | + $metaKey = $this->buildMetaKey( $metaKey, $args[ 'prefix' ] ); |
|
| 25 | + $metaValue = get_post_meta( $args[ 'id' ], $metaKey, $args[ 'single' ] ); |
|
| 26 | 26 | |
| 27 | - if( is_string( $metaValue )) { |
|
| 27 | + if( is_string( $metaValue ) ) { |
|
| 28 | 28 | $metaValue = trim( $metaValue ); |
| 29 | 29 | } |
| 30 | 30 | return empty( $metaValue ) |
| 31 | - ? $args['fallback'] |
|
| 31 | + ? $args[ 'fallback' ] |
|
| 32 | 32 | : $metaValue; |
| 33 | 33 | } |
| 34 | 34 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | protected function buildMetaKey( $metaKey, $prefix ) |
| 41 | 41 | { |
| 42 | - return ( substr( $metaKey, 0, 1 ) == '_' && !empty( $prefix )) |
|
| 42 | + return ( substr( $metaKey, 0, 1 ) == '_' && !empty( $prefix ) ) |
|
| 43 | 43 | ? sprintf( '_%s%s', rtrim( $prefix, '_' ), $metaKey ) |
| 44 | 44 | : $prefix . $metaKey; |
| 45 | 45 | } |
@@ -55,6 +55,6 @@ discard block |
||
| 55 | 55 | 'single' => true, |
| 56 | 56 | 'prefix' => Application::prefix(), |
| 57 | 57 | ]; |
| 58 | - return shortcode_atts( $defaults, array_change_key_case( $args )); |
|
| 58 | + return shortcode_atts( $defaults, array_change_key_case( $args ) ); |
|
| 59 | 59 | } |
| 60 | 60 | } |
@@ -24,20 +24,20 @@ discard block |
||
| 24 | 24 | /** |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - public $metaboxes = []; |
|
| 27 | + public $metaboxes = [ ]; |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * {@inheritdoc} |
| 31 | 31 | */ |
| 32 | 32 | public function init() |
| 33 | 33 | { |
| 34 | - $this->normalize( $this->app->config[static::ID], [ |
|
| 35 | - 'post_types' => [], |
|
| 36 | - ]); |
|
| 34 | + $this->normalize( $this->app->config[ static::ID ], [ |
|
| 35 | + 'post_types' => [ ], |
|
| 36 | + ] ); |
|
| 37 | 37 | |
| 38 | - add_filter( 'rwmb_show', [$this, 'show'], 10, 2 ); |
|
| 39 | - add_filter( 'rwmb_meta_boxes', [$this, 'register'] ); |
|
| 40 | - add_filter( 'rwmb_outer_html', [$this, 'renderField'], 10, 2 ); |
|
| 38 | + add_filter( 'rwmb_show', [ $this, 'show' ], 10, 2 ); |
|
| 39 | + add_filter( 'rwmb_meta_boxes', [ $this, 'register' ] ); |
|
| 40 | + add_filter( 'rwmb_outer_html', [ $this, 'renderField' ], 10, 2 ); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | public function filter() |
| 47 | 47 | { |
| 48 | 48 | $args = func_get_args(); |
| 49 | - $hook = sprintf( 'pollux/%s/%s', strtolower(( new Helper )->getClassname( $this )), array_shift( $args )); |
|
| 49 | + $hook = sprintf( 'pollux/%s/%s', strtolower( ( new Helper )->getClassname( $this ) ), array_shift( $args ) ); |
|
| 50 | 50 | return apply_filters_ref_array( $hook, $args ); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -56,12 +56,12 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | public function register() |
| 58 | 58 | { |
| 59 | - if( current_user_can( 'switch_themes' )) { |
|
| 59 | + if( current_user_can( 'switch_themes' ) ) { |
|
| 60 | 60 | $this->addInstructions(); |
| 61 | 61 | } |
| 62 | 62 | $metaboxes = func_num_args() |
| 63 | - ? ( new Helper )->toArray( func_get_arg(0) ) |
|
| 64 | - : []; |
|
| 63 | + ? ( new Helper )->toArray( func_get_arg( 0 ) ) |
|
| 64 | + : [ ]; |
|
| 65 | 65 | return array_merge( $metaboxes, $this->metaboxes ); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function renderField( $html, $field ) |
| 73 | 73 | { |
| 74 | - return $this->validate( $field['condition'] ) |
|
| 74 | + return $this->validate( $field[ 'condition' ] ) |
|
| 75 | 75 | ? $html |
| 76 | 76 | : ''; |
| 77 | 77 | } |
@@ -83,11 +83,11 @@ discard block |
||
| 83 | 83 | public function show( $bool, array $metabox ) |
| 84 | 84 | { |
| 85 | 85 | if( defined( 'DOING_AJAX' ) |
| 86 | - || !isset( $metabox['condition'] ) |
|
| 87 | - || !$this->hasPostType( $metabox )) { |
|
| 86 | + || !isset( $metabox[ 'condition' ] ) |
|
| 87 | + || !$this->hasPostType( $metabox ) ) { |
|
| 88 | 88 | return $bool; |
| 89 | 89 | } |
| 90 | - return $this->validate( $metabox['condition'] ); |
|
| 90 | + return $this->validate( $metabox[ 'condition' ] ); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | protected function getPostId() |
| 97 | 97 | { |
| 98 | - if( !( $postId = filter_input( INPUT_GET, 'post' ))) { |
|
| 98 | + if( !( $postId = filter_input( INPUT_GET, 'post' ) ) ) { |
|
| 99 | 99 | $postId = filter_input( INPUT_POST, 'post_ID' ); |
| 100 | 100 | } |
| 101 | 101 | return intval( $postId ); |
@@ -108,10 +108,10 @@ discard block |
||
| 108 | 108 | { |
| 109 | 109 | return array_unique( iterator_to_array( |
| 110 | 110 | new RecursiveIteratorIterator( |
| 111 | - new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' )) |
|
| 111 | + new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) ) |
|
| 112 | 112 | ), |
| 113 | 113 | false |
| 114 | - )); |
|
| 114 | + ) ); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | { |
| 122 | 122 | return PostMeta::get( $key, [ |
| 123 | 123 | 'id' => $this->getPostId(), |
| 124 | - ]); |
|
| 124 | + ] ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -129,26 +129,26 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | protected function hasPostType( array $metabox ) |
| 131 | 131 | { |
| 132 | - if( !isset( $metabox['post_types'] )) { |
|
| 132 | + if( !isset( $metabox[ 'post_types' ] ) ) { |
|
| 133 | 133 | return true; |
| 134 | 134 | } |
| 135 | - return in_array( get_post_type( $this->getPostId() ), $metabox['post_types'] ); |
|
| 135 | + return in_array( get_post_type( $this->getPostId() ), $metabox[ 'post_types' ] ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | 139 | * @return void |
| 140 | 140 | */ |
| 141 | - protected function normalize( array $metaboxes, array $defaults = [] ) |
|
| 141 | + protected function normalize( array $metaboxes, array $defaults = [ ] ) |
|
| 142 | 142 | { |
| 143 | 143 | foreach( $metaboxes as $id => $metabox ) { |
| 144 | 144 | $data = wp_parse_args( $defaults, [ |
| 145 | - 'condition' => [], |
|
| 146 | - 'fields' => [], |
|
| 145 | + 'condition' => [ ], |
|
| 146 | + 'fields' => [ ], |
|
| 147 | 147 | 'id' => $id, |
| 148 | 148 | 'slug' => $id, |
| 149 | - 'validation' => [], |
|
| 150 | - ]); |
|
| 151 | - $this->metaboxes[] = $this->setDependencies( |
|
| 149 | + 'validation' => [ ], |
|
| 150 | + ] ); |
|
| 151 | + $this->metaboxes[ ] = $this->setDependencies( |
|
| 152 | 152 | $this->normalizeThis( $metabox, $data, $id ) |
| 153 | 153 | ); |
| 154 | 154 | } |
@@ -182,10 +182,10 @@ discard block |
||
| 182 | 182 | protected function normalizeFields( array $fields, array $data, $parentId ) |
| 183 | 183 | { |
| 184 | 184 | return array_map( function( $id, $field ) use( $parentId ) { |
| 185 | - $defaults = [ |
|
| 186 | - 'attributes' => [], |
|
| 185 | + $defaults = [ |
|
| 186 | + 'attributes' => [ ], |
|
| 187 | 187 | 'class' => '', |
| 188 | - 'condition' => [], |
|
| 188 | + 'condition' => [ ], |
|
| 189 | 189 | 'depends' => '', |
| 190 | 190 | 'field_name' => $id, |
| 191 | 191 | 'id' => $id, |
@@ -219,11 +219,11 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | protected function normalizeValidation( array $validation, array $data, $parentId ) |
| 221 | 221 | { |
| 222 | - foreach( ['messages', 'rules'] as $key ) { |
|
| 223 | - if( empty( $validation[$key] ))continue; |
|
| 224 | - foreach( $validation[$key] as $id => $value ) { |
|
| 225 | - $validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value; |
|
| 226 | - unset( $validation[$key][$id] ); |
|
| 222 | + foreach( [ 'messages', 'rules' ] as $key ) { |
|
| 223 | + if( empty( $validation[ $key ] ) )continue; |
|
| 224 | + foreach( $validation[ $key ] as $id => $value ) { |
|
| 225 | + $validation[ $key ][ $this->normalizeFieldName( $id, [ 'slug' => $id ], $parentId ) ] = $value; |
|
| 226 | + unset( $validation[ $key ][ $id ] ); |
|
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | return $validation; |
@@ -234,14 +234,14 @@ discard block |
||
| 234 | 234 | */ |
| 235 | 235 | protected function setDependencies( array $metabox ) |
| 236 | 236 | { |
| 237 | - $fields = &$metabox['fields']; |
|
| 237 | + $fields = &$metabox[ 'fields' ]; |
|
| 238 | 238 | $depends = array_column( $fields, 'depends' ); |
| 239 | 239 | array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
| 240 | - if( empty( $value ))return; |
|
| 241 | - $dependency = array_search( $value, array_column( $fields, 'id' )); |
|
| 242 | - $fields[$index]['attributes']['data-depends'] = $value; |
|
| 243 | - if( !$this->getValue( $fields[$dependency]['slug'], $metabox['slug'] )) { |
|
| 244 | - $fields[$index]['class'] = trim( 'hidden ' . $fields[$index]['class'] ); |
|
| 240 | + if( empty( $value ) )return; |
|
| 241 | + $dependency = array_search( $value, array_column( $fields, 'id' ) ); |
|
| 242 | + $fields[ $index ][ 'attributes' ][ 'data-depends' ] = $value; |
|
| 243 | + if( !$this->getValue( $fields[ $dependency ][ 'slug' ], $metabox[ 'slug' ] ) ) { |
|
| 244 | + $fields[ $index ][ 'class' ] = trim( 'hidden ' . $fields[ $index ][ 'class' ] ); |
|
| 245 | 245 | } |
| 246 | 246 | }); |
| 247 | 247 | return $metabox; |
@@ -23,19 +23,19 @@ discard block |
||
| 23 | 23 | protected function addInstructions() |
| 24 | 24 | { |
| 25 | 25 | if( !$this->showInstructions() )return; |
| 26 | - $this->normalize([ |
|
| 26 | + $this->normalize( [ |
|
| 27 | 27 | 'infodiv' => [ |
| 28 | 28 | 'context' => 'side', |
| 29 | - 'fields' => [[ |
|
| 29 | + 'fields' => [ [ |
|
| 30 | 30 | 'slug' => '', |
| 31 | 31 | 'std' => $this->generateInstructions(), |
| 32 | 32 | 'type' => 'custom_html', |
| 33 | - ]], |
|
| 33 | + ] ], |
|
| 34 | 34 | 'post_types' => $this->getPostTypes(), |
| 35 | 35 | 'priority' => 'low', |
| 36 | 36 | 'title' => __( 'How to use in your theme', 'pollux' ), |
| 37 | 37 | ], |
| 38 | - ]); |
|
| 38 | + ] ); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | protected function generateInstructions() |
| 45 | 45 | { |
| 46 | 46 | $instructions = array_reduce( $this->getInstructions(), function( $html, $metabox ) { |
| 47 | - $fields = array_reduce( $metabox['fields'], function( $html, $field ) use( $metabox ) { |
|
| 48 | - return $this->validate( $field['condition'] ) |
|
| 49 | - ? $html . $this->filter( 'instruction', "PostMeta::get('{$field['slug']}');", $field, $metabox ) . PHP_EOL |
|
| 47 | + $fields = array_reduce( $metabox[ 'fields' ], function( $html, $field ) use( $metabox ) { |
|
| 48 | + return $this->validate( $field[ 'condition' ] ) |
|
| 49 | + ? $html . $this->filter( 'instruction', "PostMeta::get('{$field[ 'slug' ]}');", $field, $metabox ) . PHP_EOL |
|
| 50 | 50 | : $html; |
| 51 | 51 | }); |
| 52 | 52 | return $html . sprintf( '<p><strong>%s</strong></p><pre class="my-sites nav-tab-active misc-pub-section">%s</pre>', |
| 53 | - $metabox['title'], |
|
| 53 | + $metabox[ 'title' ], |
|
| 54 | 54 | $fields |
| 55 | 55 | ); |
| 56 | 56 | }); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | protected function getInstructions() |
| 64 | 64 | { |
| 65 | 65 | return array_filter( $this->metaboxes, function( $metabox ) { |
| 66 | - return $this->validate( $metabox['condition'] ) |
|
| 66 | + return $this->validate( $metabox[ 'condition' ] ) |
|
| 67 | 67 | && $this->hasPostType( $metabox ); |
| 68 | 68 | }); |
| 69 | 69 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | { |
| 76 | 76 | return $this->filter( 'show/instructions', count( array_filter( $this->metaboxes, function( $metabox ) { |
| 77 | 77 | return $this->show( false, $metabox ); |
| 78 | - })) > 0 ); |
|
| 78 | + }) ) > 0 ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -107,5 +107,5 @@ discard block |
||
| 107 | 107 | /** |
| 108 | 108 | * @return void |
| 109 | 109 | */ |
| 110 | - abstract protected function normalize( array $metaboxes, array $defaults = [] ); |
|
| 110 | + abstract protected function normalize( array $metaboxes, array $defaults = [ ] ); |
|
| 111 | 111 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function __construct() |
| 19 | 19 | { |
| 20 | - $this->options = get_option( Settings::id(), [] ); |
|
| 20 | + $this->options = get_option( Settings::id(), [ ] ); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $args = array_pad( $args, 2, null ); |
| 30 | 30 | $group = $this->$group; |
| 31 | - if( is_object( $group )) { |
|
| 31 | + if( is_object( $group ) ) { |
|
| 32 | 32 | return $group; |
| 33 | 33 | } |
| 34 | - return $this->get( $group, $args[0], $args[1] ); |
|
| 34 | + return $this->get( $group, $args[ 0 ], $args[ 1 ] ); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -43,11 +43,11 @@ discard block |
||
| 43 | 43 | if( $group == 'all' ) { |
| 44 | 44 | return (object) $this->options; |
| 45 | 45 | } |
| 46 | - if( empty( $group )) { |
|
| 46 | + if( empty( $group ) ) { |
|
| 47 | 47 | $group = $this->getDefaultGroup(); |
| 48 | 48 | } |
| 49 | - return isset( $this->options[$group] ) |
|
| 50 | - ? $this->options[$group] |
|
| 49 | + return isset( $this->options[ $group ] ) |
|
| 50 | + ? $this->options[ $group ] |
|
| 51 | 51 | : null; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -62,13 +62,13 @@ discard block |
||
| 62 | 62 | if( func_num_args() < 1 ) { |
| 63 | 63 | return $this->all; |
| 64 | 64 | } |
| 65 | - if( is_string( $group )) { |
|
| 65 | + if( is_string( $group ) ) { |
|
| 66 | 66 | $group = $this->$group; |
| 67 | 67 | } |
| 68 | - if( !is_array( $group )) { |
|
| 68 | + if( !is_array( $group ) ) { |
|
| 69 | 69 | return $fallback; |
| 70 | 70 | } |
| 71 | - if( is_null( $key )) { |
|
| 71 | + if( is_null( $key ) ) { |
|
| 72 | 72 | return $group; |
| 73 | 73 | } |
| 74 | 74 | return $this->getValue( $group, $key, $fallback ); |
@@ -89,11 +89,11 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | protected function getValue( array $group, $key, $fallback ) |
| 91 | 91 | { |
| 92 | - if( !array_key_exists( $key, $group )) { |
|
| 92 | + if( !array_key_exists( $key, $group ) ) { |
|
| 93 | 93 | return $fallback; |
| 94 | 94 | } |
| 95 | - return empty( $group[$key] ) && !is_null( $fallback ) |
|
| 95 | + return empty( $group[ $key ] ) && !is_null( $fallback ) |
|
| 96 | 96 | ? $fallback |
| 97 | - : $group[$key]; |
|
| 97 | + : $group[ $key ]; |
|
| 98 | 98 | } |
| 99 | 99 | } |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | { |
| 17 | 17 | public function __construct() |
| 18 | 18 | { |
| 19 | - $this->options = get_option( Archive::id(), [] ); |
|
| 19 | + $this->options = get_option( Archive::id(), [ ] ); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -4,7 +4,7 @@ |
||
| 4 | 4 | <a href="<?= $thickbox_url; ?>" id="set-post-thumbnail" class="thickbox"><?= $thumbnail; ?></a> |
| 5 | 5 | </p> |
| 6 | 6 | |
| 7 | -<?php if( get_post( $image_id )) : ?> |
|
| 7 | +<?php if( get_post( $image_id ) ) : ?> |
|
| 8 | 8 | |
| 9 | 9 | <p class="hide-if-no-js howto" id="set-post-thumbnail-desc"><?= $edit_image; ?></p> |
| 10 | 10 | <p class="hide-if-no-js"> |