Plugin Directory

Changeset 2616974


Ignore:
Timestamp:
10/20/2021 07:32:45 AM (4 years ago)
Author:
floriansimeth
Message:

Update to 2.28.1

Location:
snip-structured-data
Files:
3 edited
43 copied

Legend:

Unmodified
Added
Removed
  • snip-structured-data/tags/2.28.1/classes/controller/admin-post.php

    r2616285 r2616974  
    1111 * Class Admin_Post_Controller.
    1212 *
    13  * Helps to manage things on the dit screen.
     13 * Helps to manage things on the edit screen.
    1414 *
    1515 * @package wpbuddy\rich_snippets
     
    2929        $post_types = (array) get_option( 'wpb_rs/setting/post_types', array( 'post', 'page' ) );
    3030
    31 
    3231        foreach ( $post_types as $post_type ) {
    3332            $p = get_post_types( [ 'name' => $post_type ], 'objects' );
     
    4645                ], 10, 2 );
    4746        }
     47
     48        add_action( 'pre_get_posts', [ $this, 'filter_query_orderby' ], 100 );
     49
     50        add_filter( 'posts_clauses_request', [ $this, 'filter_query_number' ], 100, 2 );
    4851
    4952    }
     
    9093        }
    9194    }
     95
     96
     97    /**
     98     * Correctly adds the orderBy statement.
     99     *
     100     * @param \WP_Query $query
     101     *
     102     * @since 2.28.1
     103     */
     104    public function filter_query_orderby( $query ) {
     105
     106        if ( ! isset( $query->query_vars['orderby'] ) ) {
     107            return;
     108        }
     109
     110        if ( 'schema_count' !== $query->query_vars['orderby'] ) {
     111            return;
     112        }
     113
     114        if ( ! isset( $query->query_vars['meta_query'] ) ) {
     115            $query->query_vars['meta_query'] = [];
     116        }
     117
     118        $query->query_vars['meta_query'][] = [
     119            'relation' => 'OR',
     120            [
     121                'key'     => '_wpb_rs_schema',
     122                'compare' => 'EXISTS'
     123            ],
     124            [
     125                'key'     => '_wpb_rs_schema',
     126                'compare' => 'NOT EXISTS'
     127            ]
     128        ];
     129
     130        $this->meta_query_counter( count( $query->query_vars['meta_query'] ) );
     131    }
     132
     133    /**
     134     * An internal value for the meta query counter.
     135     *
     136     * @param null|int $ctn
     137     *
     138     * @return int
     139     *
     140     * @since 2.28.1
     141     */
     142    private function meta_query_counter( $ctn = null ) {
     143        static $counter;
     144
     145        if ( ! isset( $counter ) && ! is_null( $ctn ) ) {
     146            $counter = $ctn;
     147        }
     148
     149        return $counter;
     150    }
     151
     152    /**
     153     * Correctly adds the orderBy statement.
     154     *
     155     * @param string[] $clauses
     156     * @param \WP_Query $query
     157     *
     158     * @return string[]
     159     *
     160     * @since 2.28.1
     161     */
     162    public function filter_query_number( $clauses, $query ) {
     163
     164        if ( ! isset( $query->query_vars['orderby'] ) ) {
     165            return $clauses;
     166        }
     167
     168        if ( 'schema_count' !== $query->query_vars['orderby'] ) {
     169            return $clauses;
     170        }
     171
     172        $counter = $this->meta_query_counter();
     173
     174        $clauses['fields']  .= ', CAST(SUBSTR(REGEXP_SUBSTR (mt' . $counter . '.meta_value, \'^a:([0-9]+)\'), 3) AS UNSIGNED INTEGER) as schema_count';
     175        $clauses['orderby'] = 'schema_count ' . $query->query_vars['order'];
     176
     177        return $clauses;
     178    }
    92179}
  • snip-structured-data/tags/2.28.1/readme.txt

    r2616285 r2616974  
    11=== snip - Structured Data & Schema ===
    2 Stable tag: 2.28.0
     2Stable tag: 2.28.1
    33Contributors: floriansimeth
    44Donate link: https://rich-snippets.io
  • snip-structured-data/tags/2.28.1/rich-snippets-wordpress-plugin.php

    r2616285 r2616974  
    44Plugin URI: https://rich-snippets.io?pk_campaign=snip-plugin-uri
    55Description: Allows to create Rich Snippets and general structured data readable by search engines.
    6 Version: 2.28.0
     6Version: 2.28.1
    77Author: floriansimeth
    88Author URI: https://florian-simeth.de?pk_campaign=snip-author-uri
  • snip-structured-data/trunk/classes/controller/admin-post.php

    r2616285 r2616974  
    1111 * Class Admin_Post_Controller.
    1212 *
    13  * Helps to manage things on the dit screen.
     13 * Helps to manage things on the edit screen.
    1414 *
    1515 * @package wpbuddy\rich_snippets
     
    2929        $post_types = (array) get_option( 'wpb_rs/setting/post_types', array( 'post', 'page' ) );
    3030
    31 
    3231        foreach ( $post_types as $post_type ) {
    3332            $p = get_post_types( [ 'name' => $post_type ], 'objects' );
     
    4645                ], 10, 2 );
    4746        }
     47
     48        add_action( 'pre_get_posts', [ $this, 'filter_query_orderby' ], 100 );
     49
     50        add_filter( 'posts_clauses_request', [ $this, 'filter_query_number' ], 100, 2 );
    4851
    4952    }
     
    9093        }
    9194    }
     95
     96
     97    /**
     98     * Correctly adds the orderBy statement.
     99     *
     100     * @param \WP_Query $query
     101     *
     102     * @since 2.28.1
     103     */
     104    public function filter_query_orderby( $query ) {
     105
     106        if ( ! isset( $query->query_vars['orderby'] ) ) {
     107            return;
     108        }
     109
     110        if ( 'schema_count' !== $query->query_vars['orderby'] ) {
     111            return;
     112        }
     113
     114        if ( ! isset( $query->query_vars['meta_query'] ) ) {
     115            $query->query_vars['meta_query'] = [];
     116        }
     117
     118        $query->query_vars['meta_query'][] = [
     119            'relation' => 'OR',
     120            [
     121                'key'     => '_wpb_rs_schema',
     122                'compare' => 'EXISTS'
     123            ],
     124            [
     125                'key'     => '_wpb_rs_schema',
     126                'compare' => 'NOT EXISTS'
     127            ]
     128        ];
     129
     130        $this->meta_query_counter( count( $query->query_vars['meta_query'] ) );
     131    }
     132
     133    /**
     134     * An internal value for the meta query counter.
     135     *
     136     * @param null|int $ctn
     137     *
     138     * @return int
     139     *
     140     * @since 2.28.1
     141     */
     142    private function meta_query_counter( $ctn = null ) {
     143        static $counter;
     144
     145        if ( ! isset( $counter ) && ! is_null( $ctn ) ) {
     146            $counter = $ctn;
     147        }
     148
     149        return $counter;
     150    }
     151
     152    /**
     153     * Correctly adds the orderBy statement.
     154     *
     155     * @param string[] $clauses
     156     * @param \WP_Query $query
     157     *
     158     * @return string[]
     159     *
     160     * @since 2.28.1
     161     */
     162    public function filter_query_number( $clauses, $query ) {
     163
     164        if ( ! isset( $query->query_vars['orderby'] ) ) {
     165            return $clauses;
     166        }
     167
     168        if ( 'schema_count' !== $query->query_vars['orderby'] ) {
     169            return $clauses;
     170        }
     171
     172        $counter = $this->meta_query_counter();
     173
     174        $clauses['fields']  .= ', CAST(SUBSTR(REGEXP_SUBSTR (mt' . $counter . '.meta_value, \'^a:([0-9]+)\'), 3) AS UNSIGNED INTEGER) as schema_count';
     175        $clauses['orderby'] = 'schema_count ' . $query->query_vars['order'];
     176
     177        return $clauses;
     178    }
    92179}
  • snip-structured-data/trunk/readme.txt

    r2616285 r2616974  
    11=== snip - Structured Data & Schema ===
    2 Stable tag: 2.28.0
     2Stable tag: 2.28.1
    33Contributors: floriansimeth
    44Donate link: https://rich-snippets.io
  • snip-structured-data/trunk/rich-snippets-wordpress-plugin.php

    r2616285 r2616974  
    44Plugin URI: https://rich-snippets.io?pk_campaign=snip-plugin-uri
    55Description: Allows to create Rich Snippets and general structured data readable by search engines.
    6 Version: 2.28.0
     6Version: 2.28.1
    77Author: floriansimeth
    88Author URI: https://florian-simeth.de?pk_campaign=snip-author-uri
Note: See TracChangeset for help on using the changeset viewer.