Plugin Directory

Changeset 2890042


Ignore:
Timestamp:
03/30/2023 09:55:03 AM (3 years 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.2
    66Requires PHP:      7.0
    7 Stable tag:        1.0.0
     7Stable tag:        1.0.1
    88License:           GPLv2 or later
    99License URI:       http://www.gnu.org/licenses/gpl-2.0.html
     
    2121Admin menu: Tools > Which Blocks
    2222
     23== Screenshots ==
     24
     251. This is an example of the plugin results screen.
     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= 1.0.1 - 2023-03-30 =
     36* **Changed** PHP Unit Tests (props [@cadic](https://github.com/cadic) via [#12](https://github.com/cadic/which-blocks/pull/12))
     37* **Changed** Readmes and github templates (props [@cadic](https://github.com/cadic) via [#14](https://github.com/cadic/which-blocks/pull/14))
     38* **Changed** Remove composer autoloader (props [@cadic](https://github.com/cadic) via [#13](https://github.com/cadic/which-blocks/pull/13))
     39* **Changed** Replace Cypress WP Utils with the NPM package (props [@cadic](https://github.com/cadic) via [#11](https://github.com/cadic/which-blocks/pull/11))
     40* **Security** Bump webpack from 5.75.0 to 5.76.1 (props [@dependabot[bot]](https://github.com/apps/dependabot), [@cadic](https://github.com/cadic) via [#15](https://github.com/cadic/which-blocks/pull/15))
     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     * Instance of the Tools Page
     17     *
     18     * @var Tools_Page
     19     */
     20    public $tools_page = null;
     21
     22    /**
    1623     * Constructor
    1724     */
     
    2633     */
    2734    public function init() {
    28         new Tools_Page();
     35        $this->tools_page = 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     * Prepare where clauses
     54     *
     55     * @param array $args Arguments.
     56     * @return array
     57     */
     58    public static function where_clauses( $args ) {
     59        global $wpdb;
     60
     61        $where_clauses = array();
     62
     63        if ( isset( $args['post_type'] ) && is_array( $args['post_type'] ) && count( $args['post_type'] ) ) {
     64            $where_clauses[] = $wpdb->prepare( 'post_type IN (' . implode( ',', array_fill( 0, count( $args['post_type'] ), '%s' ) ) . ')', $args['post_type'] );
     65        }
     66
     67        if ( isset( $args['post_status'] ) && is_array( $args['post_status'] ) && count( $args['post_status'] ) ) {
     68            $where_clauses[] = $wpdb->prepare( 'post_status IN (' . implode( ',', array_fill( 0, count( $args['post_status'] ), '%s' ) ) . ')', $args['post_status'] );
     69        }
     70
     71        return $where_clauses;
     72    }
     73
     74    /**
     75     * Prepare SQL
     76     *
     77     * @param array $args Arguments.
     78     * @return string
     79     */
     80    public static function prepare_sql( $args ) {
     81        global $wpdb;
     82
     83        $where_clauses = self::where_clauses( $args );
     84
     85        if ( count( $where_clauses ) ) {
     86            $where = join( ' AND ', $where_clauses );
     87        } else {
     88            $where = '';
     89        }
     90
     91        $queries = array();
     92
     93        foreach ( $args['blocks'] as $block ) {
     94            if ( 'core/' === substr( $block, 0, 5 ) ) {
     95                $block_name = substr( $block, 5 );
     96            } else {
     97                $block_name = $block;
     98            }
     99            $search_pattern = '<!-- wp:' . $block_name . ' ';
     100
     101            $block_where = $wpdb->prepare( 'WHERE post_content LIKE %s', '%' . $wpdb->esc_like( $search_pattern ) . '%' );
     102            if ( $where ) {
     103                $block_where .= ' AND ' . $where;
     104            }
     105
     106            // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $block_where is prepared.
     107            $queries[] = $wpdb->prepare( "(SELECT %s as block_name, COUNT(*) as cnt FROM {$wpdb->posts} " . $block_where . ' GROUP BY %s)', $block, $block );
     108        }
     109
     110        return join( ' UNION ', $queries ) . ' ORDER BY cnt DESC';
     111    }
     112
     113    /**
     114     * Prepare arguments for get_usage
     115     *
     116     * @param array $args Search arguments.
     117     * @return array
     118     */
     119    public static function prepare_args( $args ) {
     120        $args = wp_parse_args(
     121            $args,
     122            array(
     123                'post_type'   => array( 'post', 'page' ),
     124                'post_status' => array( 'publish' ),
     125                'blocks'      => 'any',
     126                'orderby'     => 'cnt',
     127                'order'       => 'DESC',
     128            )
     129        );
     130
     131        if ( 'any' === $args['post_type'] ) {
     132            $args['post_type'] = array();
     133        } elseif ( ! is_array( $args['post_type'] ) ) {
     134            $args['post_type'] = array( $args['post_type'] );
     135        }
     136
     137        if ( 'any' === $args['post_status'] ) {
     138            $args['post_status'] = array();
     139        } elseif ( ! is_array( $args['post_status'] ) ) {
     140            $args['post_status'] = array( $args['post_status'] );
     141        }
     142
     143        if ( 'any' === $args['blocks'] ) {
     144            $args['blocks'] = array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() );
     145        } elseif ( is_array( $args['blocks'] ) ) {
     146            $args['blocks'] = $args['blocks'];
     147        } elseif ( is_string( $args['blocks'] ) ) {
     148            $args['blocks'] = array( $args['blocks'] );
     149        }
     150
     151        /**
     152         * Filter wich blocks get usage arguments before building the SQL
     153         *
     154         * @param array $args Arguments array.
     155         * @return array
     156         */
     157        return apply_filters( 'which_blocks_get_usage_args', $args );
     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 * Tested up to:    6.2
    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.2
    66Requires PHP:      7.0
    7 Stable tag:        1.0.0
     7Stable tag:        1.0.1
    88License:           GPLv2 or later
    99License URI:       http://www.gnu.org/licenses/gpl-2.0.html
     
    2121Admin menu: Tools > Which Blocks
    2222
     23== Screenshots ==
     24
     251. This is an example of the plugin results screen.
     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= 1.0.1 - 2023-03-30 =
     36* **Changed** PHP Unit Tests (props [@cadic](https://github.com/cadic) via [#12](https://github.com/cadic/which-blocks/pull/12))
     37* **Changed** Readmes and github templates (props [@cadic](https://github.com/cadic) via [#14](https://github.com/cadic/which-blocks/pull/14))
     38* **Changed** Remove composer autoloader (props [@cadic](https://github.com/cadic) via [#13](https://github.com/cadic/which-blocks/pull/13))
     39* **Changed** Replace Cypress WP Utils with the NPM package (props [@cadic](https://github.com/cadic) via [#11](https://github.com/cadic/which-blocks/pull/11))
     40* **Security** Bump webpack from 5.75.0 to 5.76.1 (props [@dependabot[bot]](https://github.com/apps/dependabot), [@cadic](https://github.com/cadic) via [#15](https://github.com/cadic/which-blocks/pull/15))
     41
    3042= 1.0.0 - 09.02.2023 =
    3143* Initial plugin release.
  • which-blocks/trunk/src/class-plugin.php

    r2862550 r2890042  
    1414
    1515    /**
     16     * Instance of the Tools Page
     17     *
     18     * @var Tools_Page
     19     */
     20    public $tools_page = null;
     21
     22    /**
    1623     * Constructor
    1724     */
     
    2633     */
    2734    public function init() {
    28         new Tools_Page();
     35        $this->tools_page = 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     * Prepare where clauses
     54     *
     55     * @param array $args Arguments.
     56     * @return array
     57     */
     58    public static function where_clauses( $args ) {
     59        global $wpdb;
     60
     61        $where_clauses = array();
     62
     63        if ( isset( $args['post_type'] ) && is_array( $args['post_type'] ) && count( $args['post_type'] ) ) {
     64            $where_clauses[] = $wpdb->prepare( 'post_type IN (' . implode( ',', array_fill( 0, count( $args['post_type'] ), '%s' ) ) . ')', $args['post_type'] );
     65        }
     66
     67        if ( isset( $args['post_status'] ) && is_array( $args['post_status'] ) && count( $args['post_status'] ) ) {
     68            $where_clauses[] = $wpdb->prepare( 'post_status IN (' . implode( ',', array_fill( 0, count( $args['post_status'] ), '%s' ) ) . ')', $args['post_status'] );
     69        }
     70
     71        return $where_clauses;
     72    }
     73
     74    /**
     75     * Prepare SQL
     76     *
     77     * @param array $args Arguments.
     78     * @return string
     79     */
     80    public static function prepare_sql( $args ) {
     81        global $wpdb;
     82
     83        $where_clauses = self::where_clauses( $args );
     84
     85        if ( count( $where_clauses ) ) {
     86            $where = join( ' AND ', $where_clauses );
     87        } else {
     88            $where = '';
     89        }
     90
     91        $queries = array();
     92
     93        foreach ( $args['blocks'] as $block ) {
     94            if ( 'core/' === substr( $block, 0, 5 ) ) {
     95                $block_name = substr( $block, 5 );
     96            } else {
     97                $block_name = $block;
     98            }
     99            $search_pattern = '<!-- wp:' . $block_name . ' ';
     100
     101            $block_where = $wpdb->prepare( 'WHERE post_content LIKE %s', '%' . $wpdb->esc_like( $search_pattern ) . '%' );
     102            if ( $where ) {
     103                $block_where .= ' AND ' . $where;
     104            }
     105
     106            // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $block_where is prepared.
     107            $queries[] = $wpdb->prepare( "(SELECT %s as block_name, COUNT(*) as cnt FROM {$wpdb->posts} " . $block_where . ' GROUP BY %s)', $block, $block );
     108        }
     109
     110        return join( ' UNION ', $queries ) . ' ORDER BY cnt DESC';
     111    }
     112
     113    /**
     114     * Prepare arguments for get_usage
     115     *
     116     * @param array $args Search arguments.
     117     * @return array
     118     */
     119    public static function prepare_args( $args ) {
     120        $args = wp_parse_args(
     121            $args,
     122            array(
     123                'post_type'   => array( 'post', 'page' ),
     124                'post_status' => array( 'publish' ),
     125                'blocks'      => 'any',
     126                'orderby'     => 'cnt',
     127                'order'       => 'DESC',
     128            )
     129        );
     130
     131        if ( 'any' === $args['post_type'] ) {
     132            $args['post_type'] = array();
     133        } elseif ( ! is_array( $args['post_type'] ) ) {
     134            $args['post_type'] = array( $args['post_type'] );
     135        }
     136
     137        if ( 'any' === $args['post_status'] ) {
     138            $args['post_status'] = array();
     139        } elseif ( ! is_array( $args['post_status'] ) ) {
     140            $args['post_status'] = array( $args['post_status'] );
     141        }
     142
     143        if ( 'any' === $args['blocks'] ) {
     144            $args['blocks'] = array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() );
     145        } elseif ( is_array( $args['blocks'] ) ) {
     146            $args['blocks'] = $args['blocks'];
     147        } elseif ( is_string( $args['blocks'] ) ) {
     148            $args['blocks'] = array( $args['blocks'] );
     149        }
     150
     151        /**
     152         * Filter wich blocks get usage arguments before building the SQL
     153         *
     154         * @param array $args Arguments array.
     155         * @return array
     156         */
     157        return apply_filters( 'which_blocks_get_usage_args', $args );
     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 * Tested up to:    6.2
    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.