Changeset 2890042
- Timestamp:
- 03/30/2023 09:55:03 AM (17 months ago)
- Location:
- which-blocks
- Files:
-
- 27 added
- 2 deleted
- 8 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
which-blocks/tags/1.0.1/readme.txt
r2862550 r2890042 3 3 Tags: block, block editor, blocks usage, statistics 4 4 Requires at least: 5.7 5 Tested up to: 6. 15 Tested up to: 6. 6 6 Requires PHP: 7.0 7 Stable tag: 1.0. 07 Stable tag: 1.0. 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 21 21 Admin menu: Tools > Which Blocks 22 22 23 24 25 26 23 27 == Installation == 28 24 29 1. Install the plugin via the plugin installer, either by searching for it or uploading a .zip file. 25 30 2. Activate the plugin. … … 28 33 == Changelog == 29 34 35 36 37 38 39 40 41 30 42 = 1.0.0 - 09.02.2023 = 31 43 * Initial plugin release. -
which-blocks/tags/1.0.1/src/class-plugin.php
r2862550 r2890042 14 14 15 15 /** 16 17 18 19 20 21 22 16 23 * Constructor 17 24 */ … … 26 33 */ 27 34 public function init() { 28 new Tools_Page();35 new Tools_Page(); 29 36 } 30 37 } -
which-blocks/tags/1.0.1/src/class-stats.php
r2862550 r2890042 24 24 global $wpdb; 25 25 26 $args = wp_parse_args( 27 $args, 28 array( 29 'post_type' => array( 'post', 'page' ), 30 'post_status' => 'publish', 31 'blocks' => 'any', 32 'orderby' => 'cnt', 33 'order' => 'DESC', 34 ) 35 ); 26 $args = self::prepare_args( $args ); 36 27 37 if ( 'any' === $args['post_type'] ) { 38 $args['post_type'] = array(); 39 } elseif ( ! is_array( $args['post_type'] ) ) { 40 $args['post_type'] = array( $args['post_type'] ); 41 } 42 43 if ( 'any' === $args['post_status'] ) { 44 $args['post_status'] = array(); 45 } elseif ( ! is_array( $args['post_status'] ) ) { 46 $args['post_status'] = array( $args['post_status'] ); 47 } 48 49 if ( 'any' === $args['blocks'] ) { 50 $blocks = array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ); 51 } elseif ( is_array( $args['blocks'] ) ) { 52 $blocks = $args['blocks']; 53 } elseif ( is_string( $args['blocks'] ) ) { 54 $blocks = array( $args['blocks'] ); 55 } 56 57 /** 58 * Filter wich blocks get usage arguments before building the SQL 59 * 60 * @param array $args Arguments array. 61 * @return array 62 */ 63 $args = apply_filters( 'which_blocks_get_usage_args', $args ); 64 65 if ( ! is_array( $blocks ) || ! count( $blocks ) ) { 28 if ( ! is_array( $args['blocks'] ) || ! count( $args['blocks'] ) ) { 66 29 return array(); 67 30 } 68 31 69 $where_clauses = array(); 70 71 if ( count( $args['post_type'] ) ) { 72 $where_clauses[] .= $wpdb->prepare( 'post_type IN (' . implode( ',', array_fill( 0, count( $args['post_type'] ), '%s' ) ) . ')', $args['post_type'] ); 73 } 74 75 if ( count( $args['post_status'] ) ) { 76 $where_clauses[] .= $wpdb->prepare( 'post_status IN (' . implode( ',', array_fill( 0, count( $args['post_status'] ), '%s' ) ) . ')', $args['post_status'] ); 77 } 78 79 if ( count( $where_clauses ) ) { 80 $where = join( ' AND ', $where_clauses ); 81 } else { 82 $where = ''; 83 } 84 85 $queries = array(); 86 87 foreach ( $blocks as $block ) { 88 if ( 'core/' === substr( $block, 0, 5 ) ) { 89 $block_name = substr( $block, 5 ); 90 } else { 91 $block_name = $block; 92 } 93 $search_pattern = '<!-- wp:' . $block_name . ' '; 94 95 $block_where = $wpdb->prepare( 'WHERE post_content LIKE %s', '%' . $wpdb->esc_like( $search_pattern ) . '%' ); 96 if ( $where ) { 97 $block_where .= ' AND ' . $where; 98 } 99 100 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $block_where is prepared. 101 $queries[] = $wpdb->prepare( "(SELECT %s as block_name, COUNT(*) as cnt FROM {$wpdb->posts} " . $block_where . ' GROUP BY %s)', $block, $block ); 102 } 103 104 $sql = join( ' UNION ', $queries ) . ' ORDER BY cnt DESC'; 32 $sql = self::prepare_sql( $args ); 105 33 106 34 $results = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Prepared on previous steps. … … 123 51 124 52 /** 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 125 161 * Sort the block statistics elements 126 162 * -
which-blocks/tags/1.0.1/which-blocks.php
r2862550 r2890042 9 9 * Domain Path: /languages 10 10 * Version: 1.0.0 11 11 12 * 12 13 * @package Which_Blocks … … 15 16 namespace WhichBlocks; 16 17 17 require_once dirname( __FILE__ ) . '/vendor/autoload.php'; 18 if ( ! class_exists( 'WP_List_Table' ) ) { 19 require_once ABSPATH . 'wp-admin/includes/screen.php'; 20 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; 21 } 22 23 require_once dirname( __FILE__ ) . '/src/class-blocks-list-table.php'; 24 require_once dirname( __FILE__ ) . '/src/class-plugin.php'; 25 require_once dirname( __FILE__ ) . '/src/class-stats.php'; 26 require_once dirname( __FILE__ ) . '/src/class-tools-page.php'; 18 27 19 28 new Plugin(); -
which-blocks/trunk/readme.txt
r2862550 r2890042 3 3 Tags: block, block editor, blocks usage, statistics 4 4 Requires at least: 5.7 5 Tested up to: 6. 15 Tested up to: 6. 6 6 Requires PHP: 7.0 7 Stable tag: 1.0. 07 Stable tag: 1.0. 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 21 21 Admin menu: Tools > Which Blocks 22 22 23 24 25 26 23 27 == Installation == 28 24 29 1. Install the plugin via the plugin installer, either by searching for it or uploading a .zip file. 25 30 2. Activate the plugin. … … 28 33 == Changelog == 29 34 35 36 37 38 39 40 41 30 42 = 1.0.0 - 09.02.2023 = 31 43 * Initial plugin release. -
which-blocks/trunk/src/class-plugin.php
r2862550 r2890042 14 14 15 15 /** 16 17 18 19 20 21 22 16 23 * Constructor 17 24 */ … … 26 33 */ 27 34 public function init() { 28 new Tools_Page();35 new Tools_Page(); 29 36 } 30 37 } -
which-blocks/trunk/src/class-stats.php
r2862550 r2890042 24 24 global $wpdb; 25 25 26 $args = wp_parse_args( 27 $args, 28 array( 29 'post_type' => array( 'post', 'page' ), 30 'post_status' => 'publish', 31 'blocks' => 'any', 32 'orderby' => 'cnt', 33 'order' => 'DESC', 34 ) 35 ); 26 $args = self::prepare_args( $args ); 36 27 37 if ( 'any' === $args['post_type'] ) { 38 $args['post_type'] = array(); 39 } elseif ( ! is_array( $args['post_type'] ) ) { 40 $args['post_type'] = array( $args['post_type'] ); 41 } 42 43 if ( 'any' === $args['post_status'] ) { 44 $args['post_status'] = array(); 45 } elseif ( ! is_array( $args['post_status'] ) ) { 46 $args['post_status'] = array( $args['post_status'] ); 47 } 48 49 if ( 'any' === $args['blocks'] ) { 50 $blocks = array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ); 51 } elseif ( is_array( $args['blocks'] ) ) { 52 $blocks = $args['blocks']; 53 } elseif ( is_string( $args['blocks'] ) ) { 54 $blocks = array( $args['blocks'] ); 55 } 56 57 /** 58 * Filter wich blocks get usage arguments before building the SQL 59 * 60 * @param array $args Arguments array. 61 * @return array 62 */ 63 $args = apply_filters( 'which_blocks_get_usage_args', $args ); 64 65 if ( ! is_array( $blocks ) || ! count( $blocks ) ) { 28 if ( ! is_array( $args['blocks'] ) || ! count( $args['blocks'] ) ) { 66 29 return array(); 67 30 } 68 31 69 $where_clauses = array(); 70 71 if ( count( $args['post_type'] ) ) { 72 $where_clauses[] .= $wpdb->prepare( 'post_type IN (' . implode( ',', array_fill( 0, count( $args['post_type'] ), '%s' ) ) . ')', $args['post_type'] ); 73 } 74 75 if ( count( $args['post_status'] ) ) { 76 $where_clauses[] .= $wpdb->prepare( 'post_status IN (' . implode( ',', array_fill( 0, count( $args['post_status'] ), '%s' ) ) . ')', $args['post_status'] ); 77 } 78 79 if ( count( $where_clauses ) ) { 80 $where = join( ' AND ', $where_clauses ); 81 } else { 82 $where = ''; 83 } 84 85 $queries = array(); 86 87 foreach ( $blocks as $block ) { 88 if ( 'core/' === substr( $block, 0, 5 ) ) { 89 $block_name = substr( $block, 5 ); 90 } else { 91 $block_name = $block; 92 } 93 $search_pattern = '<!-- wp:' . $block_name . ' '; 94 95 $block_where = $wpdb->prepare( 'WHERE post_content LIKE %s', '%' . $wpdb->esc_like( $search_pattern ) . '%' ); 96 if ( $where ) { 97 $block_where .= ' AND ' . $where; 98 } 99 100 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $block_where is prepared. 101 $queries[] = $wpdb->prepare( "(SELECT %s as block_name, COUNT(*) as cnt FROM {$wpdb->posts} " . $block_where . ' GROUP BY %s)', $block, $block ); 102 } 103 104 $sql = join( ' UNION ', $queries ) . ' ORDER BY cnt DESC'; 32 $sql = self::prepare_sql( $args ); 105 33 106 34 $results = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Prepared on previous steps. … … 123 51 124 52 /** 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 125 161 * Sort the block statistics elements 126 162 * -
which-blocks/trunk/which-blocks.php
r2862550 r2890042 9 9 * Domain Path: /languages 10 10 * Version: 1.0.0 11 11 12 * 12 13 * @package Which_Blocks … … 15 16 namespace WhichBlocks; 16 17 17 require_once dirname( __FILE__ ) . '/vendor/autoload.php'; 18 if ( ! class_exists( 'WP_List_Table' ) ) { 19 require_once ABSPATH . 'wp-admin/includes/screen.php'; 20 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; 21 } 22 23 require_once dirname( __FILE__ ) . '/src/class-blocks-list-table.php'; 24 require_once dirname( __FILE__ ) . '/src/class-plugin.php'; 25 require_once dirname( __FILE__ ) . '/src/class-stats.php'; 26 require_once dirname( __FILE__ ) . '/src/class-tools-page.php'; 18 27 19 28 new Plugin();
Note: See TracChangeset
for help on using the changeset viewer.