@@ -36,8 +36,8 @@ |
||
| 36 | 36 | $data = wp_parse_args( $data, $defaults ); |
| 37 | 37 | foreach( $defaults as $key => $value ) { |
| 38 | 38 | $method = ( new Helper )->buildMethodName( $key, 'normalize' ); |
| 39 | - if( method_exists( $this, $method )) { |
|
| 40 | - $data[$key] = $this->$method( $data[$key], $data, $id ); |
|
| 39 | + if( method_exists( $this, $method ) ) { |
|
| 40 | + $data[ $key ] = $this->$method( $data[ $key ], $data, $id ); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | return $data; |
@@ -14,10 +14,10 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | const TAXONOMY_DEFAULTS = [ |
| 16 | 16 | 'hierarchical' => true, |
| 17 | - 'labels' => [], |
|
| 17 | + 'labels' => [ ], |
|
| 18 | 18 | 'menu_name' => '', |
| 19 | 19 | 'plural' => '', |
| 20 | - 'post_types' => [], |
|
| 20 | + 'post_types' => [ ], |
|
| 21 | 21 | 'public' => true, |
| 22 | 22 | 'rewrite' => true, |
| 23 | 23 | 'show_admin_column' => true, |
@@ -28,20 +28,20 @@ discard block |
||
| 28 | 28 | /** |
| 29 | 29 | * @var array |
| 30 | 30 | */ |
| 31 | - public $taxonomies = []; |
|
| 31 | + public $taxonomies = [ ]; |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * {@inheritdoc} |
| 35 | 35 | */ |
| 36 | 36 | public function init() |
| 37 | 37 | { |
| 38 | - if( empty( $this->app->config->taxonomies ))return; |
|
| 38 | + if( empty( $this->app->config->taxonomies ) )return; |
|
| 39 | 39 | |
| 40 | 40 | $this->normalize(); |
| 41 | 41 | |
| 42 | - add_action( 'restrict_manage_posts', [ $this, 'printFilters'] ); |
|
| 43 | - add_action( 'init', [ $this, 'register'] ); |
|
| 44 | - add_filter( 'parse_query', [ $this, 'filterByTaxonomy'] ); |
|
| 42 | + add_action( 'restrict_manage_posts', [ $this, 'printFilters' ] ); |
|
| 43 | + add_action( 'init', [ $this, 'register' ] ); |
|
| 44 | + add_filter( 'parse_query', [ $this, 'filterByTaxonomy' ] ); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | if( !is_admin() || ( new Helper )->getCurrentScreen()->base != 'edit' )return; |
| 54 | 54 | $vars = &$query->query_vars; |
| 55 | 55 | foreach( array_keys( $this->taxonomies ) as $taxonomy ) { |
| 56 | - if( !isset( $vars[$taxonomy] ))return; |
|
| 57 | - if( $term = get_term_by( 'id', $vars[$taxonomy], $taxonomy )) { |
|
| 58 | - $vars[$taxonomy] = $term->slug; |
|
| 56 | + if( !isset( $vars[ $taxonomy ] ) )return; |
|
| 57 | + if( $term = get_term_by( 'id', $vars[ $taxonomy ], $taxonomy ) ) { |
|
| 58 | + $vars[ $taxonomy ] = $term->slug; |
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | return $query; |
@@ -69,18 +69,18 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | global $wp_query; |
| 71 | 71 | foreach( $this->taxonomies as $taxonomy => $args ) { |
| 72 | - if( !in_array( get_current_screen()->post_type, $args['post_types'] ))continue; |
|
| 73 | - $selected = isset( $wp_query->query[$taxonomy] ) |
|
| 74 | - ? $wp_query->query[$taxonomy] |
|
| 72 | + if( !in_array( get_current_screen()->post_type, $args[ 'post_types' ] ) )continue; |
|
| 73 | + $selected = isset( $wp_query->query[ $taxonomy ] ) |
|
| 74 | + ? $wp_query->query[ $taxonomy ] |
|
| 75 | 75 | : false; |
| 76 | - wp_dropdown_categories([ |
|
| 76 | + wp_dropdown_categories( [ |
|
| 77 | 77 | 'hide_if_empty' => true, |
| 78 | 78 | 'name' => $taxonomy, |
| 79 | 79 | 'orderby' => 'name', |
| 80 | 80 | 'selected' => $selected, |
| 81 | - 'show_option_all' => $args['labels']['all_items'], |
|
| 81 | + 'show_option_all' => $args[ 'labels' ][ 'all_items' ], |
|
| 82 | 82 | 'taxonomy' => $taxonomy, |
| 83 | - ]); |
|
| 83 | + ] ); |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | public function register() |
| 92 | 92 | { |
| 93 | 93 | array_walk( $this->taxonomies, function( $args, $taxonomy ) { |
| 94 | - register_taxonomy( $taxonomy, $args['post_types'], array_diff_key( $args, array_flip( static::CUSTOM_KEYS ))); |
|
| 95 | - foreach( $args['post_types'] as $type ) { |
|
| 94 | + register_taxonomy( $taxonomy, $args[ 'post_types' ], array_diff_key( $args, array_flip( static::CUSTOM_KEYS ) ) ); |
|
| 95 | + foreach( $args[ 'post_types' ] as $type ) { |
|
| 96 | 96 | register_taxonomy_for_object_type( $taxonomy, $type ); |
| 97 | 97 | } |
| 98 | 98 | }); |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | protected function normalize() |
| 105 | 105 | { |
| 106 | 106 | foreach( $this->app->config->taxonomies as $taxonomy => $args ) { |
| 107 | - $this->taxonomies[$taxonomy] = apply_filters( 'pollux/taxonomy/args', |
|
| 107 | + $this->taxonomies[ $taxonomy ] = apply_filters( 'pollux/taxonomy/args', |
|
| 108 | 108 | $this->normalizeThis( $args, static::TAXONOMY_DEFAULTS, $taxonomy ) |
| 109 | 109 | ); |
| 110 | 110 | } |
| 111 | 111 | $this->taxonomies = array_diff_key( |
| 112 | 112 | $this->taxonomies, |
| 113 | - get_taxonomies( ['_builtin' => true] ) |
|
| 113 | + get_taxonomies( [ '_builtin' => true ] ) |
|
| 114 | 114 | ); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | protected function normalizeLabels( $labels, array $args ) |
| 122 | 122 | { |
| 123 | - return wp_parse_args( $labels, $this->setLabels( $args )); |
|
| 123 | + return wp_parse_args( $labels, $this->setLabels( $args ) ); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | protected function normalizeMenuName( $menuname, array $args ) |
| 131 | 131 | { |
| 132 | 132 | return empty( $menuname ) |
| 133 | - ? $args['plural'] |
|
| 133 | + ? $args[ 'plural' ] |
|
| 134 | 134 | : $menuname; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -149,17 +149,17 @@ discard block |
||
| 149 | 149 | protected function setLabels( array $args ) |
| 150 | 150 | { |
| 151 | 151 | return apply_filters( 'pollux/taxonomy/labels', [ |
| 152 | - 'add_new_item' => sprintf( _x( 'Add New %s', 'Add new taxonomy', 'pollux' ), $args['single'] ), |
|
| 153 | - 'all_items' => sprintf( _x( 'All %s', 'All taxonomies', 'pollux' ), $args['plural'] ), |
|
| 154 | - 'edit_item' => sprintf( _x( 'Edit %s', 'Edit taxonomy', 'pollux' ), $args['single'] ), |
|
| 155 | - 'menu_name' => $this->normalizeMenuName( $args['menu_name'], $args ), |
|
| 156 | - 'name' => $args['plural'], |
|
| 157 | - 'new_item_name' => sprintf( _x( 'New %s Name', 'New taxonomy name', 'pollux' ), $args['single'] ), |
|
| 158 | - 'not_found' => sprintf( _x( 'No %s found', 'No taxonomies found', 'pollux' ), $args['plural'] ), |
|
| 159 | - 'search_items' => sprintf( _x( 'Search %s', 'Search taxonomies', 'pollux' ), $args['plural'] ), |
|
| 160 | - 'singular_name' => $args['single'], |
|
| 161 | - 'update_item' => sprintf( _x( 'Update %s', 'Update taxonomy', 'pollux' ), $args['single'] ), |
|
| 162 | - 'view_item' => sprintf( _x( 'View %s', 'View taxonomy', 'pollux' ), $args['single'] ), |
|
| 152 | + 'add_new_item' => sprintf( _x( 'Add New %s', 'Add new taxonomy', 'pollux' ), $args[ 'single' ] ), |
|
| 153 | + 'all_items' => sprintf( _x( 'All %s', 'All taxonomies', 'pollux' ), $args[ 'plural' ] ), |
|
| 154 | + 'edit_item' => sprintf( _x( 'Edit %s', 'Edit taxonomy', 'pollux' ), $args[ 'single' ] ), |
|
| 155 | + 'menu_name' => $this->normalizeMenuName( $args[ 'menu_name' ], $args ), |
|
| 156 | + 'name' => $args[ 'plural' ], |
|
| 157 | + 'new_item_name' => sprintf( _x( 'New %s Name', 'New taxonomy name', 'pollux' ), $args[ 'single' ] ), |
|
| 158 | + 'not_found' => sprintf( _x( 'No %s found', 'No taxonomies found', 'pollux' ), $args[ 'plural' ] ), |
|
| 159 | + 'search_items' => sprintf( _x( 'Search %s', 'Search taxonomies', 'pollux' ), $args[ 'plural' ] ), |
|
| 160 | + 'singular_name' => $args[ 'single' ], |
|
| 161 | + 'update_item' => sprintf( _x( 'Update %s', 'Update taxonomy', 'pollux' ), $args[ 'single' ] ), |
|
| 162 | + 'view_item' => sprintf( _x( 'View %s', 'View taxonomy', 'pollux' ), $args[ 'single' ] ), |
|
| 163 | 163 | ], $args ); |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -35,7 +35,9 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function init() |
| 37 | 37 | { |
| 38 | - if( empty( $this->app->config->taxonomies ))return; |
|
| 38 | + if( empty( $this->app->config->taxonomies )) { |
|
| 39 | + return; |
|
| 40 | + } |
|
| 39 | 41 | |
| 40 | 42 | $this->normalize(); |
| 41 | 43 | |
@@ -50,10 +52,14 @@ discard block |
||
| 50 | 52 | */ |
| 51 | 53 | public function filterByTaxonomy( WP_Query $query ) |
| 52 | 54 | { |
| 53 | - if( !is_admin() || ( new Helper )->getCurrentScreen()->base != 'edit' )return; |
|
| 55 | + if( !is_admin() || ( new Helper )->getCurrentScreen()->base != 'edit' ) { |
|
| 56 | + return; |
|
| 57 | + } |
|
| 54 | 58 | $vars = &$query->query_vars; |
| 55 | 59 | foreach( array_keys( $this->taxonomies ) as $taxonomy ) { |
| 56 | - if( !isset( $vars[$taxonomy] ))return; |
|
| 60 | + if( !isset( $vars[$taxonomy] )) { |
|
| 61 | + return; |
|
| 62 | + } |
|
| 57 | 63 | if( $term = get_term_by( 'id', $vars[$taxonomy], $taxonomy )) { |
| 58 | 64 | $vars[$taxonomy] = $term->slug; |
| 59 | 65 | } |
@@ -69,7 +75,9 @@ discard block |
||
| 69 | 75 | { |
| 70 | 76 | global $wp_query; |
| 71 | 77 | foreach( $this->taxonomies as $taxonomy => $args ) { |
| 72 | - if( !in_array( get_current_screen()->post_type, $args['post_types'] ))continue; |
|
| 78 | + if( !in_array( get_current_screen()->post_type, $args['post_types'] )) { |
|
| 79 | + continue; |
|
| 80 | + } |
|
| 73 | 81 | $selected = isset( $wp_query->query[$taxonomy] ) |
| 74 | 82 | ? $wp_query->query[$taxonomy] |
| 75 | 83 | : false; |
@@ -90,7 +98,8 @@ discard block |
||
| 90 | 98 | */ |
| 91 | 99 | public function register() |
| 92 | 100 | { |
| 93 | - array_walk( $this->taxonomies, function( $args, $taxonomy ) { |
|
| 101 | + array_walk( $this->taxonomies, function( $args, $taxonomy ) |
|
| 102 | + { |
|
| 94 | 103 | register_taxonomy( $taxonomy, $args['post_types'], array_diff_key( $args, array_flip( static::CUSTOM_KEYS ))); |
| 95 | 104 | foreach( $args['post_types'] as $type ) { |
| 96 | 105 | register_taxonomy_for_object_type( $taxonomy, $type ); |
@@ -45,7 +45,9 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function init() |
| 47 | 47 | { |
| 48 | - if( empty( $this->app->config->post_types ))return; |
|
| 48 | + if( empty( $this->app->config->post_types )) { |
|
| 49 | + return; |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | $this->setColumns(); |
| 51 | 53 | $this->normalize(); |
@@ -64,7 +66,8 @@ discard block |
||
| 64 | 66 | $this->types, |
| 65 | 67 | get_post_types( ['_builtin' => true] ) |
| 66 | 68 | ); |
| 67 | - array_walk( $types, function( $args, $type ) { |
|
| 69 | + array_walk( $types, function( $args, $type ) |
|
| 70 | + { |
|
| 68 | 71 | register_post_type( $type, array_diff_key( $args, array_flip( static::CUSTOM_KEYS ))); |
| 69 | 72 | }); |
| 70 | 73 | } |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | const POST_TYPE_DEFAULTS = [ |
| 17 | 17 | 'capability_type' => 'post', |
| 18 | - 'columns' => [], |
|
| 18 | + 'columns' => [ ], |
|
| 19 | 19 | 'has_archive' => false, |
| 20 | 20 | 'hierarchical' => false, |
| 21 | - 'labels' => [], |
|
| 21 | + 'labels' => [ ], |
|
| 22 | 22 | 'map_meta_cap' => true, |
| 23 | 23 | 'menu_icon' => null, |
| 24 | 24 | 'menu_name' => '', |
@@ -30,27 +30,27 @@ discard block |
||
| 30 | 30 | 'show_in_menu' => true, |
| 31 | 31 | 'show_ui' => true, |
| 32 | 32 | 'single' => '', |
| 33 | - 'supports' => ['title', 'editor', 'thumbnail'], |
|
| 34 | - 'taxonomies' => [], |
|
| 33 | + 'supports' => [ 'title', 'editor', 'thumbnail' ], |
|
| 34 | + 'taxonomies' => [ ], |
|
| 35 | 35 | ]; |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * @var array |
| 39 | 39 | */ |
| 40 | - public $types = []; |
|
| 40 | + public $types = [ ]; |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * {@inheritdoc} |
| 44 | 44 | */ |
| 45 | 45 | public function init() |
| 46 | 46 | { |
| 47 | - if( empty( $this->app->config->post_types ))return; |
|
| 47 | + if( empty( $this->app->config->post_types ) )return; |
|
| 48 | 48 | |
| 49 | 49 | $this->setColumns(); |
| 50 | 50 | $this->normalize(); |
| 51 | 51 | $this->initColumns(); |
| 52 | 52 | |
| 53 | - add_action( 'init', [$this, 'register'] ); |
|
| 53 | + add_action( 'init', [ $this, 'register' ] ); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -61,10 +61,10 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $types = array_diff_key( |
| 63 | 63 | $this->types, |
| 64 | - get_post_types( ['_builtin' => true] ) |
|
| 64 | + get_post_types( [ '_builtin' => true ] ) |
|
| 65 | 65 | ); |
| 66 | 66 | array_walk( $types, function( $args, $type ) { |
| 67 | - register_post_type( $type, array_diff_key( $args, array_flip( static::CUSTOM_KEYS ))); |
|
| 67 | + register_post_type( $type, array_diff_key( $args, array_flip( static::CUSTOM_KEYS ) ) ); |
|
| 68 | 68 | }); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | protected function normalize() |
| 75 | 75 | { |
| 76 | 76 | foreach( $this->app->config->post_types as $type => $args ) { |
| 77 | - $this->types[$type] = apply_filters( 'pollux/post_type/args', |
|
| 77 | + $this->types[ $type ] = apply_filters( 'pollux/post_type/args', |
|
| 78 | 78 | $this->normalizeThis( $args, static::POST_TYPE_DEFAULTS, $type ), |
| 79 | 79 | $type |
| 80 | 80 | ); |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | protected function normalizeLabels( $labels, array $args ) |
| 89 | 89 | { |
| 90 | - return wp_parse_args( $labels, $this->setLabels( $args )); |
|
| 90 | + return wp_parse_args( $labels, $this->setLabels( $args ) ); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | protected function normalizeMenuName( $menuname, array $args ) |
| 98 | 98 | { |
| 99 | 99 | return empty( $menuname ) |
| 100 | - ? $args['plural'] |
|
| 100 | + ? $args[ 'plural' ] |
|
| 101 | 101 | : $menuname; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -108,17 +108,17 @@ discard block |
||
| 108 | 108 | { |
| 109 | 109 | return apply_filters( 'pollux/post_type/labels', [ |
| 110 | 110 | 'add_new' => __( 'Add New', 'pollux' ), |
| 111 | - 'add_new_item' => sprintf( _x( 'Add New %s', 'Add new post', 'pollux' ), $args['single'] ), |
|
| 112 | - 'all_items' => sprintf( _x( 'All %s', 'All posts', 'pollux' ), $args['plural'] ), |
|
| 113 | - 'edit_item' => sprintf( _x( 'Edit %s', 'Edit post', 'pollux' ), $args['single'] ), |
|
| 114 | - 'menu_name' => $this->normalizeMenuName( $args['menu_name'], $args ), |
|
| 115 | - 'name' => $args['plural'], |
|
| 116 | - 'new_item' => sprintf( _x( 'New %s', 'New post', 'pollux' ), $args['single'] ), |
|
| 117 | - 'not_found' => sprintf( _x( 'No %s found', 'No posts found', 'pollux' ), $args['plural'] ), |
|
| 118 | - 'not_found_in_trash' => sprintf( _x( 'No %s found in Trash', 'No posts found in trash', 'pollux' ), $args['plural'] ), |
|
| 119 | - 'search_items' => sprintf( _x( 'Search %s', 'Search posts', 'pollux' ), $args['plural'] ), |
|
| 120 | - 'singular_name' => $args['single'], |
|
| 121 | - 'view_item' => sprintf( _x( 'View %s', 'View post', 'pollux' ), $args['single'] ), |
|
| 111 | + 'add_new_item' => sprintf( _x( 'Add New %s', 'Add new post', 'pollux' ), $args[ 'single' ] ), |
|
| 112 | + 'all_items' => sprintf( _x( 'All %s', 'All posts', 'pollux' ), $args[ 'plural' ] ), |
|
| 113 | + 'edit_item' => sprintf( _x( 'Edit %s', 'Edit post', 'pollux' ), $args[ 'single' ] ), |
|
| 114 | + 'menu_name' => $this->normalizeMenuName( $args[ 'menu_name' ], $args ), |
|
| 115 | + 'name' => $args[ 'plural' ], |
|
| 116 | + 'new_item' => sprintf( _x( 'New %s', 'New post', 'pollux' ), $args[ 'single' ] ), |
|
| 117 | + 'not_found' => sprintf( _x( 'No %s found', 'No posts found', 'pollux' ), $args[ 'plural' ] ), |
|
| 118 | + 'not_found_in_trash' => sprintf( _x( 'No %s found in Trash', 'No posts found in trash', 'pollux' ), $args[ 'plural' ] ), |
|
| 119 | + 'search_items' => sprintf( _x( 'Search %s', 'Search posts', 'pollux' ), $args[ 'plural' ] ), |
|
| 120 | + 'singular_name' => $args[ 'single' ], |
|
| 121 | + 'view_item' => sprintf( _x( 'View %s', 'View post', 'pollux' ), $args[ 'single' ] ), |
|
| 122 | 122 | ], $args ); |
| 123 | 123 | } |
| 124 | 124 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if( !function_exists( 'pollux_app' )) { |
|
| 3 | +if( !function_exists( 'pollux_app' ) ) { |
|
| 4 | 4 | function pollux_app() { |
| 5 | 5 | return GeminiLabs\Pollux\Application::getInstance(); |
| 6 | 6 | } |
@@ -1,7 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if( !function_exists( 'pollux_app' )) { |
| 4 | - function pollux_app() { |
|
| 4 | + function pollux_app() |
|
| 5 | + { |
|
| 5 | 6 | return GeminiLabs\Pollux\Application::getInstance(); |
| 6 | 7 | } |
| 7 | 8 | } |
@@ -38,7 +38,9 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public function init() |
| 40 | 40 | { |
| 41 | - if( !$this->canProceed() )return; |
|
| 41 | + if( !$this->canProceed() ) { |
|
| 42 | + return; |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | $this->normalize( $this->app->config->{static::ID} ); |
| 44 | 46 | |
@@ -123,7 +125,9 @@ discard block |
||
| 123 | 125 | */ |
| 124 | 126 | public function register() |
| 125 | 127 | { |
| 126 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 128 | + if(( new Helper )->getCurrentScreen()->id != $this->hook ) { |
|
| 129 | + return; |
|
| 130 | + } |
|
| 127 | 131 | if( $this->app->gatekeeper->hasDependency( self::DEPENDENCY )) { |
| 128 | 132 | foreach( parent::register() as $metabox ) { |
| 129 | 133 | new RWMetaBox( $metabox, static::ID, $this ); |
@@ -168,7 +172,9 @@ discard block |
||
| 168 | 172 | */ |
| 169 | 173 | public function renderFooterScript() |
| 170 | 174 | { |
| 171 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 175 | + if(( new Helper )->getCurrentScreen()->id != $this->hook ) { |
|
| 176 | + return; |
|
| 177 | + } |
|
| 172 | 178 | $this->app->render( 'settings/script', [ |
| 173 | 179 | 'confirm' => __( 'Are you sure want to do this?', 'pollux' ), |
| 174 | 180 | 'hook' => $this->hook, |
@@ -216,7 +222,9 @@ discard block |
||
| 216 | 222 | { |
| 217 | 223 | if( filter_input( INPUT_GET, 'page' ) !== static::id() |
| 218 | 224 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
| 219 | - )return; |
|
| 225 | + ) { |
|
| 226 | + return; |
|
| 227 | + } |
|
| 220 | 228 | if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) { |
| 221 | 229 | update_option( static::id(), $this->getDefaults() ); |
| 222 | 230 | add_settings_error( static::id(), 'reset', __( 'Reset successful.', 'pollux' ), 'updated' ); |
@@ -235,7 +243,8 @@ discard block |
||
| 235 | 243 | */ |
| 236 | 244 | protected function filterArrayByKey( array $array, $key ) |
| 237 | 245 | { |
| 238 | - return array_filter( $array, function( $value ) use( $key ) { |
|
| 246 | + return array_filter( $array, function( $value ) use( $key ) |
|
| 247 | + { |
|
| 239 | 248 | return !empty( $value[$key] ); |
| 240 | 249 | }); |
| 241 | 250 | } |
@@ -247,8 +256,10 @@ discard block |
||
| 247 | 256 | { |
| 248 | 257 | $metaboxes = $this->filterArrayByKey( $this->metaboxes, 'slug' ); |
| 249 | 258 | |
| 250 | - array_walk( $metaboxes, function( &$metabox ) { |
|
| 251 | - $fields = array_map( function( $field ) { |
|
| 259 | + array_walk( $metaboxes, function( &$metabox ) |
|
| 260 | + { |
|
| 261 | + $fields = array_map( function( $field ) |
|
| 262 | + { |
|
| 252 | 263 | $field = wp_parse_args( $field, ['std' => ''] ); |
| 253 | 264 | return [$field['slug'] => $field['std']]; |
| 254 | 265 | }, $this->filterArrayByKey( $metabox['fields'], 'slug' )); |
@@ -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 | /** |
@@ -72,7 +72,8 @@ discard block |
||
| 72 | 72 | 'href' => '', |
| 73 | 73 | ]); |
| 74 | 74 | $atts['class'] = trim( $atts['class'] . ' button button-small' ); |
| 75 | - $attributes = array_reduce( array_keys( $atts ), function( $carry, $key ) use( $atts ) { |
|
| 75 | + $attributes = array_reduce( array_keys( $atts ), function( $carry, $key ) use( $atts ) |
|
| 76 | + { |
|
| 76 | 77 | return $carry . sprintf( ' %s="%s"', $key, $atts[$key] ); |
| 77 | 78 | }); |
| 78 | 79 | return sprintf( '<a%s>%s</a>', $attributes, $title ); |
@@ -151,7 +152,9 @@ discard block |
||
| 151 | 152 | protected function buildMessage( array $messages ) |
| 152 | 153 | { |
| 153 | 154 | foreach( $messages as $key => &$message ) { |
| 154 | - if( !is_wp_error( $message ))continue; |
|
| 155 | + if( !is_wp_error( $message )) { |
|
| 156 | + continue; |
|
| 157 | + } |
|
| 155 | 158 | $message = $message->get_error_message(); |
| 156 | 159 | } |
| 157 | 160 | return wpautop( implode( PHP_EOL . PHP_EOL, $messages )); |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | $method = strtolower( $name ); |
| 31 | 31 | $status = substr( $method, 3 ); |
| 32 | - if( 'add' == substr( $method, 0, 3 ) && in_array( $status, ['error', 'info', 'success', 'warning'] )) { |
|
| 33 | - return call_user_func_array( [$this, 'addNotice'], array_merge( [$status], $args )); |
|
| 32 | + if( 'add' == substr( $method, 0, 3 ) && in_array( $status, [ 'error', 'info', 'success', 'warning' ] ) ) { |
|
| 33 | + return call_user_func_array( [ $this, 'addNotice' ], array_merge( [ $status ], $args ) ); |
|
| 34 | 34 | } |
| 35 | - throw new BadMethodCallException( sprintf( 'Not a valid method: %s', $name )); |
|
| 35 | + throw new BadMethodCallException( sprintf( 'Not a valid method: %s', $name ) ); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function __get( $property ) |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | if( $property == 'all' ) { |
| 41 | 41 | return $this->app->notices; |
| 42 | 42 | } |
| 43 | - throw new Exception( sprintf( 'Not a valid property: %s', $property )); |
|
| 43 | + throw new Exception( sprintf( 'Not a valid property: %s', $property ) ); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -48,28 +48,28 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function activateButton( array $plugin ) |
| 50 | 50 | { |
| 51 | - $actionUrl = self_admin_url( sprintf( 'options-general.php?page=%s&action=activate&plugin=%s', $this->app->id, $plugin['plugin'] )); |
|
| 52 | - return $this->button( sprintf( '%s %s', __( 'Activate', 'pollux' ), $plugin['name'] ), [ |
|
| 53 | - 'data-name' => $plugin['name'], |
|
| 54 | - 'data-plugin' => $plugin['plugin'], |
|
| 55 | - 'data-slug' => $plugin['slug'], |
|
| 56 | - 'href' => wp_nonce_url( $actionUrl, sprintf( 'activate-plugin_%s', $plugin['plugin'] )), |
|
| 57 | - ]); |
|
| 51 | + $actionUrl = self_admin_url( sprintf( 'options-general.php?page=%s&action=activate&plugin=%s', $this->app->id, $plugin[ 'plugin' ] ) ); |
|
| 52 | + return $this->button( sprintf( '%s %s', __( 'Activate', 'pollux' ), $plugin[ 'name' ] ), [ |
|
| 53 | + 'data-name' => $plugin[ 'name' ], |
|
| 54 | + 'data-plugin' => $plugin[ 'plugin' ], |
|
| 55 | + 'data-slug' => $plugin[ 'slug' ], |
|
| 56 | + 'href' => wp_nonce_url( $actionUrl, sprintf( 'activate-plugin_%s', $plugin[ 'plugin' ] ) ), |
|
| 57 | + ] ); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * @param string $title |
| 62 | 62 | * @return string |
| 63 | 63 | */ |
| 64 | - public function button( $title, array $atts = [] ) |
|
| 64 | + public function button( $title, array $atts = [ ] ) |
|
| 65 | 65 | { |
| 66 | 66 | $atts = wp_parse_args( $atts, [ |
| 67 | 67 | 'class' => '', |
| 68 | 68 | 'href' => '', |
| 69 | - ]); |
|
| 70 | - $atts['class'] = trim( $atts['class'] . ' button button-small' ); |
|
| 69 | + ] ); |
|
| 70 | + $atts[ 'class' ] = trim( $atts[ 'class' ] . ' button button-small' ); |
|
| 71 | 71 | $attributes = array_reduce( array_keys( $atts ), function( $carry, $key ) use( $atts ) { |
| 72 | - return $carry . sprintf( ' %s="%s"', $key, $atts[$key] ); |
|
| 72 | + return $carry . sprintf( ' %s="%s"', $key, $atts[ $key ] ); |
|
| 73 | 73 | }); |
| 74 | 74 | return sprintf( '<a%s>%s</a>', $attributes, $title ); |
| 75 | 75 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | if( $unset ) { |
| 83 | 83 | $index = array_search( $notice, $this->app->notices ); |
| 84 | 84 | if( $index !== false ) { |
| 85 | - unset( $this->app->notices[$index] ); |
|
| 85 | + unset( $this->app->notices[ $index ] ); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | return $this->buildNotice( $notice ); |
@@ -93,13 +93,13 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function installButton( array $plugin ) |
| 95 | 95 | { |
| 96 | - $actionUrl = self_admin_url( sprintf( 'update.php?action=install-plugin&plugin=%s', $plugin['slug'] )); |
|
| 97 | - return $this->button( sprintf( '%s %s', __( 'Install', 'pollux' ), $plugin['name'] ), [ |
|
| 98 | - 'data-name' => $plugin['name'], |
|
| 99 | - 'data-plugin' => $plugin['plugin'], |
|
| 100 | - 'data-slug' => $plugin['slug'], |
|
| 101 | - 'href' => wp_nonce_url( $actionUrl, sprintf( 'install-plugin_%s', $plugin['slug'] )), |
|
| 102 | - ]); |
|
| 96 | + $actionUrl = self_admin_url( sprintf( 'update.php?action=install-plugin&plugin=%s', $plugin[ 'slug' ] ) ); |
|
| 97 | + return $this->button( sprintf( '%s %s', __( 'Install', 'pollux' ), $plugin[ 'name' ] ), [ |
|
| 98 | + 'data-name' => $plugin[ 'name' ], |
|
| 99 | + 'data-plugin' => $plugin[ 'plugin' ], |
|
| 100 | + 'data-slug' => $plugin[ 'slug' ], |
|
| 101 | + 'href' => wp_nonce_url( $actionUrl, sprintf( 'install-plugin_%s', $plugin[ 'slug' ] ) ), |
|
| 102 | + ] ); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | public function updateButton( array $plugin ) |
| 109 | 109 | { |
| 110 | - $actionUrl = self_admin_url( sprintf( 'update.php?action=upgrade-plugin&plugin=%s', $plugin['plugin'] )); |
|
| 111 | - return $this->button( sprintf( '%s %s', __( 'Update', 'pollux' ), $plugin['name'] ), [ |
|
| 112 | - 'data-name' => $plugin['name'], |
|
| 113 | - 'data-plugin' => $plugin['plugin'], |
|
| 114 | - 'data-slug' => $plugin['slug'], |
|
| 115 | - 'href' => wp_nonce_url( $actionUrl, sprintf( 'upgrade-plugin_%s', $plugin['plugin'] )), |
|
| 116 | - ]); |
|
| 110 | + $actionUrl = self_admin_url( sprintf( 'update.php?action=upgrade-plugin&plugin=%s', $plugin[ 'plugin' ] ) ); |
|
| 111 | + return $this->button( sprintf( '%s %s', __( 'Update', 'pollux' ), $plugin[ 'name' ] ), [ |
|
| 112 | + 'data-name' => $plugin[ 'name' ], |
|
| 113 | + 'data-plugin' => $plugin[ 'plugin' ], |
|
| 114 | + 'data-slug' => $plugin[ 'slug' ], |
|
| 115 | + 'href' => wp_nonce_url( $actionUrl, sprintf( 'upgrade-plugin_%s', $plugin[ 'plugin' ] ) ), |
|
| 116 | + ] ); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | protected function addNotice( $type, $messages, $dismissible = true ) |
| 135 | 135 | { |
| 136 | - $this->app->notices[] = [ |
|
| 136 | + $this->app->notices[ ] = [ |
|
| 137 | 137 | 'dismissible' => $dismissible, |
| 138 | - 'message' => $this->buildMessage( array_filter( (array) $messages )), |
|
| 138 | + 'message' => $this->buildMessage( array_filter( (array) $messages ) ), |
|
| 139 | 139 | 'type' => $type, |
| 140 | 140 | ]; |
| 141 | 141 | $this->app->notices = array_unique( $this->app->notices, SORT_REGULAR ); |
@@ -147,10 +147,10 @@ discard block |
||
| 147 | 147 | protected function buildMessage( array $messages ) |
| 148 | 148 | { |
| 149 | 149 | foreach( $messages as $key => &$message ) { |
| 150 | - if( !is_wp_error( $message ))continue; |
|
| 150 | + if( !is_wp_error( $message ) )continue; |
|
| 151 | 151 | $message = $message->get_error_message(); |
| 152 | 152 | } |
| 153 | - return wpautop( implode( PHP_EOL . PHP_EOL, $messages )); |
|
| 153 | + return wpautop( implode( PHP_EOL . PHP_EOL, $messages ) ); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -158,10 +158,10 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | protected function buildNotice( array $notice ) |
| 160 | 160 | { |
| 161 | - $class = sprintf( 'notice notice-%s', $notice['type'] ); |
|
| 162 | - if( $notice['dismissible'] ) { |
|
| 161 | + $class = sprintf( 'notice notice-%s', $notice[ 'type' ] ); |
|
| 162 | + if( $notice[ 'dismissible' ] ) { |
|
| 163 | 163 | $class .= ' is-dismissible'; |
| 164 | 164 | } |
| 165 | - return sprintf( '<div class="pollux-notice %s">%s</div>', $class, $notice['message'] ); |
|
| 165 | + return sprintf( '<div class="pollux-notice %s">%s</div>', $class, $notice[ 'message' ] ); |
|
| 166 | 166 | } |
| 167 | 167 | } |
@@ -124,6 +124,7 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | + * @param string $plugin |
|
| 127 | 128 | * @return bool |
| 128 | 129 | */ |
| 129 | 130 | public function hasDependency( $plugin ) |
@@ -384,6 +385,7 @@ discard block |
||
| 384 | 385 | } |
| 385 | 386 | |
| 386 | 387 | /** |
| 388 | + * @param string $key |
|
| 387 | 389 | * @return array|string |
| 388 | 390 | */ |
| 389 | 391 | protected function getPluginRequirements( $plugin, $key = null ) |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | 'meta-box/meta-box.php' => 'Meta Box|4.11|https://wordpress.org/plugins/meta-box/', |
| 15 | 15 | ]; |
| 16 | 16 | |
| 17 | - public $errors = []; |
|
| 17 | + public $errors = [ ]; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * @var Notice |
@@ -29,17 +29,17 @@ discard block |
||
| 29 | 29 | public function __construct( $plugin ) |
| 30 | 30 | { |
| 31 | 31 | $this->plugin = $plugin; |
| 32 | - add_action( 'admin_init', [$this, 'init'] ); |
|
| 32 | + add_action( 'admin_init', [ $this, 'init' ] ); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function init() |
| 36 | 36 | { |
| 37 | 37 | $this->notice = pollux_app()->make( 'Notice' ); |
| 38 | 38 | |
| 39 | - add_action( 'current_screen', [$this, 'activatePlugin'] ); |
|
| 40 | - add_action( 'wp_ajax_pollux/dependency/activate_url', [$this, 'ajaxActivatePluginLink'] ); |
|
| 41 | - add_action( 'admin_notices', [$this, 'printNotices'] ); |
|
| 42 | - add_action( 'current_screen', [$this, 'setDependencyNotice'] ); |
|
| 39 | + add_action( 'current_screen', [ $this, 'activatePlugin' ] ); |
|
| 40 | + add_action( 'wp_ajax_pollux/dependency/activate_url', [ $this, 'ajaxActivatePluginLink' ] ); |
|
| 41 | + add_action( 'admin_notices', [ $this, 'printNotices' ] ); |
|
| 42 | + add_action( 'current_screen', [ $this, 'setDependencyNotice' ] ); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $plugin = filter_input( INPUT_GET, 'plugin' ); |
| 54 | 54 | check_admin_referer( 'activate-plugin_' . $plugin ); |
| 55 | 55 | $result = activate_plugin( $plugin, null, is_network_admin(), true ); |
| 56 | - if( is_wp_error( $result )) { |
|
| 56 | + if( is_wp_error( $result ) ) { |
|
| 57 | 57 | wp_die( $result->get_error_message() ); |
| 58 | 58 | } |
| 59 | 59 | wp_safe_redirect( wp_get_referer() ); |
@@ -67,19 +67,19 @@ discard block |
||
| 67 | 67 | { |
| 68 | 68 | check_ajax_referer( 'updates' ); |
| 69 | 69 | $plugin = filter_input( INPUT_POST, 'plugin' ); |
| 70 | - if( !$this->isPluginDependency( $plugin )) { |
|
| 70 | + if( !$this->isPluginDependency( $plugin ) ) { |
|
| 71 | 71 | wp_send_json_error(); |
| 72 | 72 | } |
| 73 | - $activateUrl = add_query_arg([ |
|
| 74 | - '_wpnonce' => wp_create_nonce( sprintf( 'activate-plugin_%s', $plugin )), |
|
| 73 | + $activateUrl = add_query_arg( [ |
|
| 74 | + '_wpnonce' => wp_create_nonce( sprintf( 'activate-plugin_%s', $plugin ) ), |
|
| 75 | 75 | 'action' => 'activate', |
| 76 | 76 | 'page' => pollux_app()->id, |
| 77 | 77 | 'plugin' => $plugin, |
| 78 | - ], self_admin_url( 'options-general.php' )); |
|
| 79 | - wp_send_json_success([ |
|
| 78 | + ], self_admin_url( 'options-general.php' ) ); |
|
| 79 | + wp_send_json_success( [ |
|
| 80 | 80 | 'activate_url' => $activateUrl, |
| 81 | 81 | filter_input( INPUT_POST, 'type' ) => $plugin, |
| 82 | - ]); |
|
| 82 | + ] ); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function hasDependency( $plugin ) |
| 89 | 89 | { |
| 90 | - if( !$this->isPluginDependency( $plugin )) { |
|
| 90 | + if( !$this->isPluginDependency( $plugin ) ) { |
|
| 91 | 91 | return true; |
| 92 | 92 | } |
| 93 | 93 | return $this->isPluginInstalled( $plugin ) && $this->isPluginValid( $plugin ); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | public function hasPendingDependencies() |
| 100 | 100 | { |
| 101 | 101 | foreach( static::DEPENDENCIES as $plugin => $data ) { |
| 102 | - if( !$this->isPluginDependency( $plugin ))continue; |
|
| 102 | + if( !$this->isPluginDependency( $plugin ) )continue; |
|
| 103 | 103 | $this->isPluginActive( $plugin ); |
| 104 | 104 | $this->isPluginVersionValid( $plugin ); |
| 105 | 105 | } |
@@ -147,17 +147,17 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | public function isPluginVersionValid( $plugin ) |
| 149 | 149 | { |
| 150 | - if( !$this->isPluginDependency( $plugin )) { |
|
| 150 | + if( !$this->isPluginDependency( $plugin ) ) { |
|
| 151 | 151 | return true; |
| 152 | 152 | } |
| 153 | - if( !$this->isPluginInstalled( $plugin )) { |
|
| 153 | + if( !$this->isPluginInstalled( $plugin ) ) { |
|
| 154 | 154 | return false; |
| 155 | 155 | } |
| 156 | 156 | return $this->catchError( $plugin, 'wrong_version', version_compare( |
| 157 | 157 | $this->getPluginRequirements( $plugin, 'version' ), |
| 158 | - $this->getAllPlugins()[$plugin]['Version'], |
|
| 158 | + $this->getAllPlugins()[ $plugin ][ 'Version' ], |
|
| 159 | 159 | '<=' |
| 160 | - )); |
|
| 160 | + ) ); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | __( 'Pollux requires the latest version of the following plugins', 'pollux' ), |
| 184 | 184 | $this->getDependencyLinks() |
| 185 | 185 | ); |
| 186 | - $this->notice->addWarning( [$message, $this->getDependencyActions()] ); |
|
| 186 | + $this->notice->addWarning( [ $message, $this->getDependencyActions() ] ); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -194,13 +194,13 @@ discard block |
||
| 194 | 194 | */ |
| 195 | 195 | protected function catchError( $plugin, $error, $isValid ) |
| 196 | 196 | { |
| 197 | - if( !$isValid && $this->isPluginDependency( $plugin )) { |
|
| 198 | - if( !isset( $this->errors[$plugin] )) { |
|
| 199 | - $this->errors[$plugin] = []; |
|
| 197 | + if( !$isValid && $this->isPluginDependency( $plugin ) ) { |
|
| 198 | + if( !isset( $this->errors[ $plugin ] ) ) { |
|
| 199 | + $this->errors[ $plugin ] = [ ]; |
|
| 200 | 200 | } |
| 201 | - $this->errors[$plugin] = array_keys( array_flip( |
|
| 202 | - array_merge( $this->errors[$plugin], [$error] ) |
|
| 203 | - )); |
|
| 201 | + $this->errors[ $plugin ] = array_keys( array_flip( |
|
| 202 | + array_merge( $this->errors[ $plugin ], [ $error ] ) |
|
| 203 | + ) ); |
|
| 204 | 204 | } |
| 205 | 205 | return $isValid; |
| 206 | 206 | } |
@@ -221,14 +221,14 @@ discard block |
||
| 221 | 221 | { |
| 222 | 222 | $actions = ''; |
| 223 | 223 | foreach( $this->errors as $plugin => $errors ) { |
| 224 | - if( in_array( 'not_found', $errors ) && current_user_can( 'install_plugins' )) { |
|
| 225 | - $actions .= $this->notice->installButton( $this->getPluginRequirements( $plugin )); |
|
| 224 | + if( in_array( 'not_found', $errors ) && current_user_can( 'install_plugins' ) ) { |
|
| 225 | + $actions .= $this->notice->installButton( $this->getPluginRequirements( $plugin ) ); |
|
| 226 | 226 | } |
| 227 | - else if( in_array( 'wrong_version', $errors ) && current_user_can( 'update_plugins' )) { |
|
| 228 | - $actions .= $this->notice->updateButton( $this->getPluginInformation( $plugin )); |
|
| 227 | + else if( in_array( 'wrong_version', $errors ) && current_user_can( 'update_plugins' ) ) { |
|
| 228 | + $actions .= $this->notice->updateButton( $this->getPluginInformation( $plugin ) ); |
|
| 229 | 229 | } |
| 230 | - else if( in_array( 'inactive', $errors ) && current_user_can( 'activate_plugins' )) { |
|
| 231 | - $actions .= $this->notice->activateButton( $this->getPluginInformation( $plugin )); |
|
| 230 | + else if( in_array( 'inactive', $errors ) && current_user_can( 'activate_plugins' ) ) { |
|
| 231 | + $actions .= $this->notice->activateButton( $this->getPluginInformation( $plugin ) ); |
|
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | return $actions; |
@@ -250,10 +250,10 @@ discard block |
||
| 250 | 250 | protected function getMustUsePlugins() |
| 251 | 251 | { |
| 252 | 252 | $plugins = get_mu_plugins(); |
| 253 | - if( in_array( 'Bedrock Autoloader', array_column( $plugins, 'Name' ))) { |
|
| 253 | + if( in_array( 'Bedrock Autoloader', array_column( $plugins, 'Name' ) ) ) { |
|
| 254 | 254 | $autoloadedPlugins = get_site_option( 'bedrock_autoloader' ); |
| 255 | - if( !empty( $autoloadedPlugins['plugins'] )) { |
|
| 256 | - return array_merge( $plugins, $autoloadedPlugins['plugins'] ); |
|
| 255 | + if( !empty( $autoloadedPlugins[ 'plugins' ] ) ) { |
|
| 256 | + return array_merge( $plugins, $autoloadedPlugins[ 'plugins' ] ); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | return $plugins; |
@@ -264,8 +264,8 @@ discard block |
||
| 264 | 264 | */ |
| 265 | 265 | protected function getPlugin( $plugin ) |
| 266 | 266 | { |
| 267 | - if( $this->isPluginInstalled( $plugin )) { |
|
| 268 | - return $this->getAllPlugins()[$plugin]; |
|
| 267 | + if( $this->isPluginInstalled( $plugin ) ) { |
|
| 268 | + return $this->getAllPlugins()[ $plugin ]; |
|
| 269 | 269 | } |
| 270 | 270 | return false; |
| 271 | 271 | } |
@@ -275,18 +275,18 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | protected function getPluginData( $plugin, $data, $key = null ) |
| 277 | 277 | { |
| 278 | - if( !is_array( $data )) { |
|
| 279 | - throw new Exception( sprintf( 'Plugin information not found for: %s', $plugin )); |
|
| 278 | + if( !is_array( $data ) ) { |
|
| 279 | + throw new Exception( sprintf( 'Plugin information not found for: %s', $plugin ) ); |
|
| 280 | 280 | } |
| 281 | - $data['plugin'] = $plugin; |
|
| 282 | - $data['slug'] = $this->getPluginSlug( $plugin ); |
|
| 281 | + $data[ 'plugin' ] = $plugin; |
|
| 282 | + $data[ 'slug' ] = $this->getPluginSlug( $plugin ); |
|
| 283 | 283 | $data = array_change_key_case( $data ); |
| 284 | - if( is_null( $key )) { |
|
| 284 | + if( is_null( $key ) ) { |
|
| 285 | 285 | return $data; |
| 286 | 286 | } |
| 287 | 287 | $key = strtolower( $key ); |
| 288 | - return isset( $data[$key] ) |
|
| 289 | - ? $data[$key] |
|
| 288 | + return isset( $data[ $key ] ) |
|
| 289 | + ? $data[ $key ] |
|
| 290 | 290 | : ''; |
| 291 | 291 | } |
| 292 | 292 | |
@@ -310,9 +310,9 @@ discard block |
||
| 310 | 310 | $data = $this->getPluginRequirements( $plugin ); |
| 311 | 311 | } |
| 312 | 312 | return sprintf( '<span class="plugin-%s"><a href="%s">%s</a></span>', |
| 313 | - $data['slug'], |
|
| 314 | - $data['pluginuri'], |
|
| 315 | - $data['name'] |
|
| 313 | + $data[ 'slug' ], |
|
| 314 | + $data[ 'pluginuri' ], |
|
| 315 | + $data[ 'name' ] |
|
| 316 | 316 | ); |
| 317 | 317 | } |
| 318 | 318 | |
@@ -321,9 +321,9 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | protected function getPluginRequirements( $plugin, $key = null ) |
| 323 | 323 | { |
| 324 | - $keys = ['Name', 'Version', 'PluginURI']; |
|
| 324 | + $keys = [ 'Name', 'Version', 'PluginURI' ]; |
|
| 325 | 325 | $requirements = $this->isPluginDependency( $plugin ) |
| 326 | - ? array_pad( explode( '|', static::DEPENDENCIES[$plugin] ), 3, '' ) |
|
| 326 | + ? array_pad( explode( '|', static::DEPENDENCIES[ $plugin ] ), 3, '' ) |
|
| 327 | 327 | : array_fill( 0, 3, '' ); |
| 328 | 328 | return $this->getPluginData( $plugin, array_combine( $keys, $requirements ), $key ); |
| 329 | 329 | } |
@@ -333,6 +333,6 @@ discard block |
||
| 333 | 333 | */ |
| 334 | 334 | protected function getPluginSlug( $plugin ) |
| 335 | 335 | { |
| 336 | - return substr( $plugin, 0, strrpos( $plugin, '/' )); |
|
| 336 | + return substr( $plugin, 0, strrpos( $plugin, '/' ) ); |
|
| 337 | 337 | } |
| 338 | 338 | } |
@@ -49,7 +49,9 @@ discard block |
||
| 49 | 49 | { |
| 50 | 50 | if( get_current_screen()->id != sprintf( 'settings_page_%s', pollux_app()->id ) |
| 51 | 51 | || filter_input( INPUT_GET, 'action' ) != 'activate' |
| 52 | - )return; |
|
| 52 | + ) { |
|
| 53 | + return; |
|
| 54 | + } |
|
| 53 | 55 | $plugin = filter_input( INPUT_GET, 'plugin' ); |
| 54 | 56 | check_admin_referer( 'activate-plugin_' . $plugin ); |
| 55 | 57 | $result = activate_plugin( $plugin, null, is_network_admin(), true ); |
@@ -99,7 +101,9 @@ discard block |
||
| 99 | 101 | public function hasPendingDependencies() |
| 100 | 102 | { |
| 101 | 103 | foreach( static::DEPENDENCIES as $plugin => $data ) { |
| 102 | - if( !$this->isPluginDependency( $plugin ))continue; |
|
| 104 | + if( !$this->isPluginDependency( $plugin )) { |
|
| 105 | + continue; |
|
| 106 | + } |
|
| 103 | 107 | $this->isPluginActive( $plugin ); |
| 104 | 108 | $this->isPluginVersionValid( $plugin ); |
| 105 | 109 | } |
@@ -178,7 +182,9 @@ discard block |
||
| 178 | 182 | if( get_current_screen()->id != 'settings_page_pollux' |
| 179 | 183 | || pollux_app()->config->disable_config |
| 180 | 184 | || !$this->hasPendingDependencies() |
| 181 | - )return; |
|
| 185 | + ) { |
|
| 186 | + return; |
|
| 187 | + } |
|
| 182 | 188 | $message = sprintf( '<strong>%s:</strong> %s', |
| 183 | 189 | __( 'Pollux requires the latest version of the following plugins', 'pollux' ), |
| 184 | 190 | $this->getDependencyLinks() |
@@ -239,7 +245,8 @@ discard block |
||
| 239 | 245 | */ |
| 240 | 246 | protected function getDependencyLinks() |
| 241 | 247 | { |
| 242 | - return array_reduce( array_keys( $this->errors ), function( $carry, $plugin ) { |
|
| 248 | + return array_reduce( array_keys( $this->errors ), function( $carry, $plugin ) |
|
| 249 | + { |
|
| 243 | 250 | return $carry . $this->getPluginLink( $plugin ); |
| 244 | 251 | }); |
| 245 | 252 | } |
@@ -27,15 +27,15 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | remove_action( 'welcome_panel', 'wp_welcome_panel' ); |
| 29 | 29 | |
| 30 | - add_action( 'init', [$this, 'disable'] ); |
|
| 31 | - add_action( 'wp_dashboard_setup', [$this, 'modifyDashboardWidgets'] ); |
|
| 32 | - add_action( 'welcome_panel', [$this, 'modifyWelcomePanel'] ); |
|
| 33 | - add_action( 'admin_bar_menu', [$this, 'removeFromAdminBar'], 999 ); |
|
| 34 | - add_action( 'admin_menu', [$this, 'removeFromAdminMenu'] ); |
|
| 35 | - add_action( 'admin_init', [$this, 'unregisterDashboardWidgets'] ); |
|
| 36 | - add_action( 'widgets_init', [$this, 'unregisterWidgets'], 1 ); |
|
| 37 | - add_filter( 'posts_results', [$this, 'filterPostQuery'] ); |
|
| 38 | - add_filter( 'pre_get_posts', [$this, 'filterSearchQuery'] ); |
|
| 30 | + add_action( 'init', [ $this, 'disable' ] ); |
|
| 31 | + add_action( 'wp_dashboard_setup', [ $this, 'modifyDashboardWidgets' ] ); |
|
| 32 | + add_action( 'welcome_panel', [ $this, 'modifyWelcomePanel' ] ); |
|
| 33 | + add_action( 'admin_bar_menu', [ $this, 'removeFromAdminBar' ], 999 ); |
|
| 34 | + add_action( 'admin_menu', [ $this, 'removeFromAdminMenu' ] ); |
|
| 35 | + add_action( 'admin_init', [ $this, 'unregisterDashboardWidgets' ] ); |
|
| 36 | + add_action( 'widgets_init', [ $this, 'unregisterWidgets' ], 1 ); |
|
| 37 | + add_filter( 'posts_results', [ $this, 'filterPostQuery' ] ); |
|
| 38 | + add_filter( 'pre_get_posts', [ $this, 'filterSearchQuery' ] ); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -44,14 +44,14 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function disable() |
| 46 | 46 | { |
| 47 | - if( !in_array(( new Helper )->getCurrentScreen()->pagenow, [ |
|
| 47 | + if( !in_array( ( new Helper )->getCurrentScreen()->pagenow, [ |
|
| 48 | 48 | 'edit.php', 'edit-tags.php', 'post-new.php', |
| 49 | - ]))return; |
|
| 49 | + ] ) )return; |
|
| 50 | 50 | |
| 51 | 51 | if( !filter_input_array( INPUT_GET, [ |
| 52 | 52 | 'post_type' => FILTER_DEFAULT, |
| 53 | 53 | 'taxonomy' => FILTER_DEFAULT, |
| 54 | - ])) { |
|
| 54 | + ] ) ) { |
|
| 55 | 55 | wp_safe_redirect( get_admin_url(), 301 ); |
| 56 | 56 | exit; |
| 57 | 57 | } |
@@ -69,12 +69,12 @@ discard block |
||
| 69 | 69 | * @return array |
| 70 | 70 | * @filter posts_results |
| 71 | 71 | */ |
| 72 | - public function filterPostQuery( $posts = [] ) |
|
| 72 | + public function filterPostQuery( $posts = [ ] ) |
|
| 73 | 73 | { |
| 74 | 74 | global $wp_query; |
| 75 | 75 | return $this->isAdmin() || strpos( $wp_query->request, "wp_posts.post_type = 'post'" ) === false |
| 76 | 76 | ? $posts |
| 77 | - : []; |
|
| 77 | + : [ ]; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | if( $this->isAdmin() || !$query->is_main_query() || !is_search() ) { |
| 87 | 87 | return $query; |
| 88 | 88 | } |
| 89 | - $post_types = get_post_types( ['exclude_from_search' => false ] ); |
|
| 90 | - unset( $post_types['post'] ); |
|
| 89 | + $post_types = get_post_types( [ 'exclude_from_search' => false ] ); |
|
| 90 | + unset( $post_types[ 'post' ] ); |
|
| 91 | 91 | $query->set( 'post_type', array_values( $post_types ) ); |
| 92 | 92 | return $query; |
| 93 | 93 | } |
@@ -98,12 +98,12 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | public function modifyDashboardWidgets() |
| 100 | 100 | { |
| 101 | - if( !is_blog_admin() || !current_user_can( 'edit_posts' ))return; |
|
| 101 | + if( !is_blog_admin() || !current_user_can( 'edit_posts' ) )return; |
|
| 102 | 102 | |
| 103 | 103 | global $wp_meta_boxes; |
| 104 | - $widgets = &$wp_meta_boxes['dashboard']['normal']['core']; |
|
| 105 | - if( !isset( $widgets['dashboard_right_now']['callback'] ))return; |
|
| 106 | - $widgets['dashboard_right_now']['callback'] = function() { |
|
| 104 | + $widgets = &$wp_meta_boxes[ 'dashboard' ][ 'normal' ][ 'core' ]; |
|
| 105 | + if( !isset( $widgets[ 'dashboard_right_now' ][ 'callback' ] ) )return; |
|
| 106 | + $widgets[ 'dashboard_right_now' ][ 'callback' ] = function() { |
|
| 107 | 107 | ob_start(); |
| 108 | 108 | wp_dashboard_right_now(); |
| 109 | 109 | echo preg_replace( '/<li class="post-count">(.*?)<\/li>/', '', ob_get_clean() ); |
@@ -23,7 +23,9 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function init() |
| 25 | 25 | { |
| 26 | - if( !$this->app->config->disable_posts )return; |
|
| 26 | + if( !$this->app->config->disable_posts ) { |
|
| 27 | + return; |
|
| 28 | + } |
|
| 27 | 29 | |
| 28 | 30 | remove_action( 'welcome_panel', 'wp_welcome_panel' ); |
| 29 | 31 | |
@@ -46,7 +48,9 @@ discard block |
||
| 46 | 48 | { |
| 47 | 49 | if( !in_array(( new Helper )->getCurrentScreen()->pagenow, [ |
| 48 | 50 | 'edit.php', 'edit-tags.php', 'post-new.php', |
| 49 | - ]))return; |
|
| 51 | + ])) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 50 | 54 | |
| 51 | 55 | if( !filter_input_array( INPUT_GET, [ |
| 52 | 56 | 'post_type' => FILTER_DEFAULT, |
@@ -98,12 +102,17 @@ discard block |
||
| 98 | 102 | */ |
| 99 | 103 | public function modifyDashboardWidgets() |
| 100 | 104 | { |
| 101 | - if( !is_blog_admin() || !current_user_can( 'edit_posts' ))return; |
|
| 105 | + if( !is_blog_admin() || !current_user_can( 'edit_posts' )) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 102 | 108 | |
| 103 | 109 | global $wp_meta_boxes; |
| 104 | 110 | $widgets = &$wp_meta_boxes['dashboard']['normal']['core']; |
| 105 | - if( !isset( $widgets['dashboard_right_now']['callback'] ))return; |
|
| 106 | - $widgets['dashboard_right_now']['callback'] = function() { |
|
| 111 | + if( !isset( $widgets['dashboard_right_now']['callback'] )) { |
|
| 112 | + return; |
|
| 113 | + } |
|
| 114 | + $widgets['dashboard_right_now']['callback'] = function() |
|
| 115 | + { |
|
| 107 | 116 | ob_start(); |
| 108 | 117 | wp_dashboard_right_now(); |
| 109 | 118 | echo preg_replace( '/<li class="post-count">(.*?)<\/li>/', '', ob_get_clean() ); |
@@ -13,10 +13,10 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | public function buildClassName( $name, $path = '' ) |
| 15 | 15 | { |
| 16 | - $className = array_map( 'ucfirst', array_map( 'strtolower', preg_split( '/[-_]/', $name ))); |
|
| 16 | + $className = array_map( 'ucfirst', array_map( 'strtolower', preg_split( '/[-_]/', $name ) ) ); |
|
| 17 | 17 | $className = implode( '', $className ); |
| 18 | 18 | return !empty( $path ) |
| 19 | - ? str_replace( '\\\\', '\\', sprintf( '%s\%s', $path, $className )) |
|
| 19 | + ? str_replace( '\\\\', '\\', sprintf( '%s\%s', $path, $className ) ) |
|
| 20 | 20 | : $className; |
| 21 | 21 | } |
| 22 | 22 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | public function buildMethodName( $name, $prefix = 'get' ) |
| 29 | 29 | { |
| 30 | - return lcfirst( $this->buildClassName( $prefix . '-' . $name )); |
|
| 30 | + return lcfirst( $this->buildClassName( $prefix . '-' . $name ) ); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -63,10 +63,10 @@ discard block |
||
| 63 | 63 | public function getCurrentScreen() |
| 64 | 64 | { |
| 65 | 65 | global $hook_suffix, $pagenow; |
| 66 | - if( function_exists( 'get_current_screen' )) { |
|
| 66 | + if( function_exists( 'get_current_screen' ) ) { |
|
| 67 | 67 | $screen = get_current_screen(); |
| 68 | 68 | } |
| 69 | - if( empty( $screen )) { |
|
| 69 | + if( empty( $screen ) ) { |
|
| 70 | 70 | $screen = new \stdClass(); |
| 71 | 71 | $screen->base = $screen->id = $hook_suffix; |
| 72 | 72 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function startsWith( $needle, $haystack ) |
| 83 | 83 | { |
| 84 | - return substr( $haystack, 0, strlen( $needle )) === $needle; |
|
| 84 | + return substr( $haystack, 0, strlen( $needle ) ) === $needle; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |