Plugin Directory

Changeset 2890042

Timestamp:
03/30/2023 09:55:03 AM (17 months ago)
Author:
cadic
Message:

Update to version 1.0.1 from GitHub

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  
    33Tags:              block, block editor, blocks usage, statistics
    44Requires at least: 5.7
    5 Tested up to:      6.1
     5Tested up to:      6.
    66Requires PHP:      7.0
    7 Stable tag:        1.0.0
     7Stable tag:        1.0.
    88License:           GPLv2 or later
    99License URI:       http://www.gnu.org/licenses/gpl-2.0.html
     
    2121Admin menu: Tools > Which Blocks
    2222
     23
     24
     25
     26
    2327== Installation ==
     28
    24291. Install the plugin via the plugin installer, either by searching for it or uploading a .zip file.
    25302. Activate the plugin.
     
    2833== Changelog ==
    2934
     35
     36
     37
     38
     39
     40
     41
    3042= 1.0.0 - 09.02.2023 =
    3143* Initial plugin release.
  • which-blocks/tags/1.0.1/src/class-plugin.php

    r2862550 r2890042  
    1414
    1515    /**
     16
     17
     18
     19
     20
     21
     22
    1623     * Constructor
    1724     */
     
    2633     */
    2734    public function init() {
    28         new Tools_Page();
     35        new Tools_Page();
    2936    }
    3037}
  • which-blocks/tags/1.0.1/src/class-stats.php

    r2862550 r2890042  
    2424        global $wpdb;
    2525
    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 );
    3627
    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'] ) ) {
    6629            return array();
    6730        }
    6831
    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 );
    10533
    10634        $results = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Prepared on previous steps.
     
    12351
    12452    /**
     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
    125161     * Sort the block statistics elements
    126162     *
  • which-blocks/tags/1.0.1/which-blocks.php

    r2862550 r2890042  
    99 * Domain Path:     /languages
    1010 * Version:         1.0.0
     11
    1112 *
    1213 * @package         Which_Blocks
     
    1516namespace WhichBlocks;
    1617
    17 require_once dirname( __FILE__ ) . '/vendor/autoload.php';
     18if ( ! 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
     23require_once dirname( __FILE__ ) . '/src/class-blocks-list-table.php';
     24require_once dirname( __FILE__ ) . '/src/class-plugin.php';
     25require_once dirname( __FILE__ ) . '/src/class-stats.php';
     26require_once dirname( __FILE__ ) . '/src/class-tools-page.php';
    1827
    1928new Plugin();
  • which-blocks/trunk/readme.txt

    r2862550 r2890042  
    33Tags:              block, block editor, blocks usage, statistics
    44Requires at least: 5.7
    5 Tested up to:      6.1
     5Tested up to:      6.
    66Requires PHP:      7.0
    7 Stable tag:        1.0.0
     7Stable tag:        1.0.
    88License:           GPLv2 or later
    99License URI:       http://www.gnu.org/licenses/gpl-2.0.html
     
    2121Admin menu: Tools > Which Blocks
    2222
     23
     24
     25
     26
    2327== Installation ==
     28
    24291. Install the plugin via the plugin installer, either by searching for it or uploading a .zip file.
    25302. Activate the plugin.
     
    2833== Changelog ==
    2934
     35
     36
     37
     38
     39
     40
     41
    3042= 1.0.0 - 09.02.2023 =
    3143* Initial plugin release.
  • which-blocks/trunk/src/class-plugin.php

    r2862550 r2890042  
    1414
    1515    /**
     16
     17
     18
     19
     20
     21
     22
    1623     * Constructor
    1724     */
     
    2633     */
    2734    public function init() {
    28         new Tools_Page();
     35        new Tools_Page();
    2936    }
    3037}
  • which-blocks/trunk/src/class-stats.php

    r2862550 r2890042  
    2424        global $wpdb;
    2525
    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 );
    3627
    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'] ) ) {
    6629            return array();
    6730        }
    6831
    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 );
    10533
    10634        $results = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Prepared on previous steps.
     
    12351
    12452    /**
     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
    125161     * Sort the block statistics elements
    126162     *
  • which-blocks/trunk/which-blocks.php

    r2862550 r2890042  
    99 * Domain Path:     /languages
    1010 * Version:         1.0.0
     11
    1112 *
    1213 * @package         Which_Blocks
     
    1516namespace WhichBlocks;
    1617
    17 require_once dirname( __FILE__ ) . '/vendor/autoload.php';
     18if ( ! 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
     23require_once dirname( __FILE__ ) . '/src/class-blocks-list-table.php';
     24require_once dirname( __FILE__ ) . '/src/class-plugin.php';
     25require_once dirname( __FILE__ ) . '/src/class-stats.php';
     26require_once dirname( __FILE__ ) . '/src/class-tools-page.php';
    1827
    1928new Plugin();
Note: See TracChangeset for help on using the changeset viewer.