Plugin Directory

Changeset 3264568


Ignore:
Timestamp:
03/31/2025 03:56:40 PM (12 months ago)
Author:
wpengine
Message:

Tagging version 0.2.76

Location:
atlas-search
Files:
18 edited
1 copied

Legend:

Unmodified
Added
Removed
  • atlas-search/tags/0.2.76/README.txt

    r3261003 r3264568  
    33Tested up to: 6.7.1
    44Requires PHP: 7.4
    5 Stable tag: 0.2.75
     5Stable tag: 0.2.76
    66License: GPLv2 or later
    77License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5656
    5757== Changelog ==
     58= 0.2.76 =
     59* **Updated:** Recommendations Block Options
     60* **Fixed:** Recommendations block error handling
     61* **Fixed:** Set limit for posts
     62
    5863= 0.2.75 =
    5964* **Added:** Semantic & Hybrid Search allows multiple fields to be selected
  • atlas-search/tags/0.2.76/atlas-search.php

    r3261003 r3264568  
    1616 * Plugin URI:        https://developers.wpengine.com/
    1717 * Description:       Searching WordPress data with WP Engine Smart Search.
    18  * Version:           0.2.75
     18 * Version:           0.2.76
    1919 * Author:            WP Engine
    2020 * Author URI:        https://wpengine.com/
     
    4141 * Rename this for your plugin and update it as you release new versions.
    4242 */
    43 define( 'WPE_SMART_SEARCH_VERSION', '0.2.75' );
     43define( 'WPE_SMART_SEARCH_VERSION', '0.2.76' );
    4444
    4545/**
  • atlas-search/tags/0.2.76/build/recommendations-block/index.asset.php

    r3247243 r3264568  
    1 <?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-hooks', 'wp-i18n'), 'version' => '42d78a282262aad644fb');
     1<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-hooks', 'wp-i18n'), 'version' => '16bbceb5ee694ae1f81f');
  • atlas-search/tags/0.2.76/build/recommendations-block/index.js

    r3247243 r3264568  
    1 (()=>{"use strict";var e={};function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function r(e,r,n){return(r=function(e){var r=function(e){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}e.n=t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const i=window.React;var a=e.n(i);const c=window.wp.i18n,s=window.wp.blocks,l=window.wp.hooks,p=window.wp.compose,m=window.wp.blockEditor,u=window.wp.components,d="wpengine-smart-search/recommendations";(0,s.registerBlockVariation)("core/query",{name:d,title:(0,c.__)("Smart Search Recommendations","wpengine-smart-search"),description:(0,c.__)("Fetches recommended posts from WP Engine Smart Search","wpengine-smart-search"),icon:"database",attributes:{namespace:d,query:{postType:"post",perPage:3,pages:1,order:"asc",orderBy:"title",offset:0,exclude:[],inherit:!1},postLimit:5,recommendationsType:"trending"},scope:["inserter"],isActive:["namespace"],innerBlocks:[["core/post-template",{layout:{type:"grid",columnCount:3}},[["core/post-featured-image"],["core/post-title",{level:3,isLink:!0}]]]]}),(0,l.addFilter)("blocks.registerBlockType",d,((e,t)=>("core/query"===t&&(e.attributes=o(o({},e.attributes),{},{postLimit:{type:"number",default:5},recommendationsType:{type:"string",default:"trending"}})),e))),(0,l.addFilter)("editor.BlockEdit","core/query",(0,p.createHigherOrderComponent)((e=>t=>{if("wpengine-smart-search/recommendations"!==t.attributes.namespace)return a().createElement(e,t);const{attributes:r,setAttributes:n}=t,{postLimit:o,recommendationsType:i}=r;return a().createElement(a().Fragment,null,a().createElement(m.InspectorControls,null,a().createElement(u.PanelBody,{title:(0,c.__)("Recommendation Settings","wpengine-smart-search"),initialOpen:!0},a().createElement(u.RangeControl,{title:"PostLimit",label:(0,c.__)("Count","wpengine-smart-search"),value:o,onChange:e=>n({postLimit:e}),min:1,max:20}),a().createElement(u.SelectControl,{title:"RecommendationsType",label:(0,c.__)("RecommendationsType","wpengine-smart-search"),value:i,options:[{label:"Trending Posts",value:"trending"},{label:"Related Posts",value:"related"}],onChange:e=>n({recommendationsType:e})}))),a().createElement(e,t))}),"withQueryLoopControls"))})();
     1(()=>{"use strict";var e={};function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function r(e,r,n){return(r=function(e){var r=function(e){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}e.n=t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const i=window.React;var a=e.n(i);const c=window.wp.i18n,s=window.wp.blocks,l=window.wp.hooks,p=window.wp.compose,m=window.wp.blockEditor,u=window.wp.components,y="wpengine-smart-search/recommendations";(0,s.registerBlockVariation)("core/query",{name:y,title:(0,c.__)("Smart Search Recommendations","wpengine-smart-search"),description:(0,c.__)("Fetches recommended posts from WP Engine Smart Search","wpengine-smart-search"),icon:"database",attributes:{namespace:y,query:{postType:"post",offset:0,exclude:[],inherit:!1,perPage:5,sticky:"exclude"},postLimit:5,recommendationsType:"trending"},allowedControls:["postType","sticky","taxQuery"],scope:["inserter"],isActive:["namespace"],innerBlocks:[["core/post-template",{layout:{type:"grid",columnCount:3}},[["core/post-featured-image"],["core/post-title",{level:3,isLink:!0}]]]]}),(0,l.addFilter)("blocks.registerBlockType",y,((e,t)=>("core/query"===t&&(e.attributes=o(o({},e.attributes),{},{postLimit:{type:"number",default:5},recommendationsType:{type:"string",default:"trending"}})),e))),(0,l.addFilter)("editor.BlockEdit","core/query",(0,p.createHigherOrderComponent)((e=>t=>{if("wpengine-smart-search/recommendations"!==t.attributes.namespace)return a().createElement(e,t);const{attributes:r,setAttributes:n}=t,{postLimit:i,recommendationsType:s}=r;return a().createElement(a().Fragment,null,a().createElement(m.InspectorControls,null,a().createElement(u.PanelBody,{title:(0,c.__)("Recommendation Settings","wpengine-smart-search"),initialOpen:!0},a().createElement(u.RangeControl,{title:"PostLimit",label:(0,c.__)("Count","wpengine-smart-search"),value:i,onChange:e=>{n({postLimit:e,query:o(o({},r.query),{},{perPage:e})})},min:1,max:20}),a().createElement(u.SelectControl,{title:"RecommendationsType",label:(0,c.__)("RecommendationsType","wpengine-smart-search"),value:s,options:[{label:"Trending Posts",value:"trending"},{label:"Related Posts",value:"related"}],onChange:e=>n({recommendationsType:e})}))),a().createElement(e,t))}),"withQueryLoopControls"))})();
  • atlas-search/tags/0.2.76/build/recommendations-block/query-loop.php

    r3261003 r3264568  
    2121        $GLOBALS['rec_block'] = $block;
    2222
     23        if ( isset( $block['attrs']['query'] ) ) {
     24            $block['attrs']['query']['postsPerPage'] = (int) ( $block['attrs']['postLimit'] ?? 5 );
     25        }
     26
    2327        add_filter(
    2428            'query_loop_block_query_vars',
     
    3741    do_action( 'qm/debug', $block['attrs'] );
    3842
    39     $post_limit           = (int) ( $block['attrs']['postLimit'] ?? 6 );
     43    $post_limit           = (int) ( $block['attrs']['postLimit'] ?? 5 );
    4044    $recommendations_type = (string) ( $block['attrs']['recommendationsType'] ?? 'trending' );
    4145    if ( 'trending' === $recommendations_type ) {
     
    5559    }
    5660
     61    if ( empty( $popular_ids ) ) {
     62        return $query;
     63    }
     64
    5765    $query['post__in'] = $popular_ids;
    58     $query['orderby']  = 'post__in';
    5966
    60     // Remove the filter after it has been applied to avoid affecting other query loops.
     67    $query['orderby']        = 'post__in';
     68    $query['posts_per_page'] = $post_limit;
     69
    6170    remove_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\modify_query_vars' );
    6271
     
    9099function get_trending_posts( $count ) {
    91100    $vars = array( 'count' => $count );
    92     $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars );
    93     $docs = $data['data']['recommendations']['trendingDocuments'];
    94     return format_docs_as_ids( $docs );
     101
     102    try {
     103        $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars );
     104
     105        if ( isset( $data['errors'] ) ) {
     106            return array();
     107        }
     108
     109        $docs = $data['data']['recommendations']['trendingDocuments'] ?? array();
     110
     111        return format_docs_as_ids( $docs );
     112
     113    } catch ( \Exception $e ) {
     114        return array();
     115    }
    95116}
    96117
     118
     119
    97120function format_docs_as_ids( $docs ) {
     121    if ( empty( $docs ) ) {
     122        return array();
     123    }
    98124    $ids = array();
    99125
     
    111137        'doc_id' => $post_type . ':' . $post_id,
    112138    );
    113     $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars );
    114     $docs = $data['data']['recommendations']['relatedDocuments'];
    115     return format_docs_as_ids( $docs );
     139
     140    try {
     141        $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars );
     142
     143        $docs = $data['data']['recommendations']['relatedDocuments'] ?? array();
     144        if ( isset( $data['errors'] ) ) {
     145            return array();
     146        }
     147
     148        return format_docs_as_ids( $docs );
     149
     150    } catch ( \Exception $e ) {
     151        return array();
     152    }
    116153}
  • atlas-search/tags/0.2.76/helper/search/search.php

    r3239389 r3264568  
    294294         * Sometimes WP plugin developers calling with negative number expect to get all posts
    295295         */
    296         $posts_per_page = ( $posts_per_page < 0 ) ? 1000 : $posts_per_page;
    297         $query_offset   = $query->get( 'offset', false );
    298         $offset         = false !== $query_offset ? $query_offset : self::get_offset( $page_number, $posts_per_page );
    299         $filter         = $this->generate_filters( $post_types, $query, $excluded_post_types );
     296        $posts_per_page = ( $posts_per_page < 0 || $posts_per_page > 1000 ) ? 1000 : $posts_per_page;
     297        $query->set( 'posts_per_page', $posts_per_page );
     298        $query_offset = $query->get( 'offset', false );
     299        $offset       = false !== $query_offset ? $query_offset : self::get_offset( $page_number, $posts_per_page );
     300        $filter       = $this->generate_filters( $post_types, $query, $excluded_post_types );
    300301
    301302        if ( 0 == $posts_per_page ) {
  • atlas-search/tags/0.2.76/src/blocks/recommendations-block/index.js

    r3247243 r3264568  
    2323    query: {
    2424      postType: 'post',
    25       perPage: 3,
    26       pages: 1,
    27       order: 'asc',
    28       orderBy: 'title',
    2925      offset: 0,
    3026      exclude: [],
    3127      inherit: false,
     28      perPage: 5,
     29      sticky: 'exclude',
    3230    },
    3331    postLimit: 5,
    3432    recommendationsType: 'trending',
    3533  },
     34  allowedControls: ['postType', 'sticky', 'taxQuery'],
    3635  scope: ['inserter'],
    3736  isActive: ['namespace'],
     
    9796                label={__('Count', 'wpengine-smart-search')}
    9897                value={postLimit}
    99                 onChange={(newPostLimit) =>
    100                   setAttributes({ postLimit: newPostLimit })
    101                 }
     98                onChange={(newPostLimit) => {
     99                  setAttributes({
     100                    postLimit: newPostLimit,
     101                    query: { ...attributes.query, perPage: newPostLimit },
     102                  });
     103                }}
    102104                min={1}
    103105                max={20}
  • atlas-search/tags/0.2.76/src/blocks/recommendations-block/index.test.js

    r3247243 r3264568  
    6767    });
    6868
    69     expect(setAttributes).toHaveBeenCalledWith({ postLimit: '10' });
     69    expect(setAttributes).toHaveBeenCalledWith({
     70      postLimit: '10',
     71      query: { perPage: '10' },
     72    });
    7073  });
    7174
  • atlas-search/tags/0.2.76/src/blocks/recommendations-block/query-loop.php

    r3261003 r3264568  
    2121        $GLOBALS['rec_block'] = $block;
    2222
     23        if ( isset( $block['attrs']['query'] ) ) {
     24            $block['attrs']['query']['postsPerPage'] = (int) ( $block['attrs']['postLimit'] ?? 5 );
     25        }
     26
    2327        add_filter(
    2428            'query_loop_block_query_vars',
     
    3741    do_action( 'qm/debug', $block['attrs'] );
    3842
    39     $post_limit           = (int) ( $block['attrs']['postLimit'] ?? 6 );
     43    $post_limit           = (int) ( $block['attrs']['postLimit'] ?? 5 );
    4044    $recommendations_type = (string) ( $block['attrs']['recommendationsType'] ?? 'trending' );
    4145    if ( 'trending' === $recommendations_type ) {
     
    5559    }
    5660
     61    if ( empty( $popular_ids ) ) {
     62        return $query;
     63    }
     64
    5765    $query['post__in'] = $popular_ids;
    58     $query['orderby']  = 'post__in';
    5966
    60     // Remove the filter after it has been applied to avoid affecting other query loops.
     67    $query['orderby']        = 'post__in';
     68    $query['posts_per_page'] = $post_limit;
     69
    6170    remove_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\modify_query_vars' );
    6271
     
    9099function get_trending_posts( $count ) {
    91100    $vars = array( 'count' => $count );
    92     $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars );
    93     $docs = $data['data']['recommendations']['trendingDocuments'];
    94     return format_docs_as_ids( $docs );
     101
     102    try {
     103        $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars );
     104
     105        if ( isset( $data['errors'] ) ) {
     106            return array();
     107        }
     108
     109        $docs = $data['data']['recommendations']['trendingDocuments'] ?? array();
     110
     111        return format_docs_as_ids( $docs );
     112
     113    } catch ( \Exception $e ) {
     114        return array();
     115    }
    95116}
    96117
     118
     119
    97120function format_docs_as_ids( $docs ) {
     121    if ( empty( $docs ) ) {
     122        return array();
     123    }
    98124    $ids = array();
    99125
     
    111137        'doc_id' => $post_type . ':' . $post_id,
    112138    );
    113     $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars );
    114     $docs = $data['data']['recommendations']['relatedDocuments'];
    115     return format_docs_as_ids( $docs );
     139
     140    try {
     141        $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars );
     142
     143        $docs = $data['data']['recommendations']['relatedDocuments'] ?? array();
     144        if ( isset( $data['errors'] ) ) {
     145            return array();
     146        }
     147
     148        return format_docs_as_ids( $docs );
     149
     150    } catch ( \Exception $e ) {
     151        return array();
     152    }
    116153}
  • atlas-search/trunk/README.txt

    r3261003 r3264568  
    33Tested up to: 6.7.1
    44Requires PHP: 7.4
    5 Stable tag: 0.2.75
     5Stable tag: 0.2.76
    66License: GPLv2 or later
    77License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5656
    5757== Changelog ==
     58= 0.2.76 =
     59* **Updated:** Recommendations Block Options
     60* **Fixed:** Recommendations block error handling
     61* **Fixed:** Set limit for posts
     62
    5863= 0.2.75 =
    5964* **Added:** Semantic & Hybrid Search allows multiple fields to be selected
  • atlas-search/trunk/atlas-search.php

    r3261003 r3264568  
    1616 * Plugin URI:        https://developers.wpengine.com/
    1717 * Description:       Searching WordPress data with WP Engine Smart Search.
    18  * Version:           0.2.75
     18 * Version:           0.2.76
    1919 * Author:            WP Engine
    2020 * Author URI:        https://wpengine.com/
     
    4141 * Rename this for your plugin and update it as you release new versions.
    4242 */
    43 define( 'WPE_SMART_SEARCH_VERSION', '0.2.75' );
     43define( 'WPE_SMART_SEARCH_VERSION', '0.2.76' );
    4444
    4545/**
  • atlas-search/trunk/build/recommendations-block/index.asset.php

    r3247243 r3264568  
    1 <?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-hooks', 'wp-i18n'), 'version' => '42d78a282262aad644fb');
     1<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-hooks', 'wp-i18n'), 'version' => '16bbceb5ee694ae1f81f');
  • atlas-search/trunk/build/recommendations-block/index.js

    r3247243 r3264568  
    1 (()=>{"use strict";var e={};function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function r(e,r,n){return(r=function(e){var r=function(e){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}e.n=t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const i=window.React;var a=e.n(i);const c=window.wp.i18n,s=window.wp.blocks,l=window.wp.hooks,p=window.wp.compose,m=window.wp.blockEditor,u=window.wp.components,d="wpengine-smart-search/recommendations";(0,s.registerBlockVariation)("core/query",{name:d,title:(0,c.__)("Smart Search Recommendations","wpengine-smart-search"),description:(0,c.__)("Fetches recommended posts from WP Engine Smart Search","wpengine-smart-search"),icon:"database",attributes:{namespace:d,query:{postType:"post",perPage:3,pages:1,order:"asc",orderBy:"title",offset:0,exclude:[],inherit:!1},postLimit:5,recommendationsType:"trending"},scope:["inserter"],isActive:["namespace"],innerBlocks:[["core/post-template",{layout:{type:"grid",columnCount:3}},[["core/post-featured-image"],["core/post-title",{level:3,isLink:!0}]]]]}),(0,l.addFilter)("blocks.registerBlockType",d,((e,t)=>("core/query"===t&&(e.attributes=o(o({},e.attributes),{},{postLimit:{type:"number",default:5},recommendationsType:{type:"string",default:"trending"}})),e))),(0,l.addFilter)("editor.BlockEdit","core/query",(0,p.createHigherOrderComponent)((e=>t=>{if("wpengine-smart-search/recommendations"!==t.attributes.namespace)return a().createElement(e,t);const{attributes:r,setAttributes:n}=t,{postLimit:o,recommendationsType:i}=r;return a().createElement(a().Fragment,null,a().createElement(m.InspectorControls,null,a().createElement(u.PanelBody,{title:(0,c.__)("Recommendation Settings","wpengine-smart-search"),initialOpen:!0},a().createElement(u.RangeControl,{title:"PostLimit",label:(0,c.__)("Count","wpengine-smart-search"),value:o,onChange:e=>n({postLimit:e}),min:1,max:20}),a().createElement(u.SelectControl,{title:"RecommendationsType",label:(0,c.__)("RecommendationsType","wpengine-smart-search"),value:i,options:[{label:"Trending Posts",value:"trending"},{label:"Related Posts",value:"related"}],onChange:e=>n({recommendationsType:e})}))),a().createElement(e,t))}),"withQueryLoopControls"))})();
     1(()=>{"use strict";var e={};function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function r(e,r,n){return(r=function(e){var r=function(e){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}e.n=t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const i=window.React;var a=e.n(i);const c=window.wp.i18n,s=window.wp.blocks,l=window.wp.hooks,p=window.wp.compose,m=window.wp.blockEditor,u=window.wp.components,y="wpengine-smart-search/recommendations";(0,s.registerBlockVariation)("core/query",{name:y,title:(0,c.__)("Smart Search Recommendations","wpengine-smart-search"),description:(0,c.__)("Fetches recommended posts from WP Engine Smart Search","wpengine-smart-search"),icon:"database",attributes:{namespace:y,query:{postType:"post",offset:0,exclude:[],inherit:!1,perPage:5,sticky:"exclude"},postLimit:5,recommendationsType:"trending"},allowedControls:["postType","sticky","taxQuery"],scope:["inserter"],isActive:["namespace"],innerBlocks:[["core/post-template",{layout:{type:"grid",columnCount:3}},[["core/post-featured-image"],["core/post-title",{level:3,isLink:!0}]]]]}),(0,l.addFilter)("blocks.registerBlockType",y,((e,t)=>("core/query"===t&&(e.attributes=o(o({},e.attributes),{},{postLimit:{type:"number",default:5},recommendationsType:{type:"string",default:"trending"}})),e))),(0,l.addFilter)("editor.BlockEdit","core/query",(0,p.createHigherOrderComponent)((e=>t=>{if("wpengine-smart-search/recommendations"!==t.attributes.namespace)return a().createElement(e,t);const{attributes:r,setAttributes:n}=t,{postLimit:i,recommendationsType:s}=r;return a().createElement(a().Fragment,null,a().createElement(m.InspectorControls,null,a().createElement(u.PanelBody,{title:(0,c.__)("Recommendation Settings","wpengine-smart-search"),initialOpen:!0},a().createElement(u.RangeControl,{title:"PostLimit",label:(0,c.__)("Count","wpengine-smart-search"),value:i,onChange:e=>{n({postLimit:e,query:o(o({},r.query),{},{perPage:e})})},min:1,max:20}),a().createElement(u.SelectControl,{title:"RecommendationsType",label:(0,c.__)("RecommendationsType","wpengine-smart-search"),value:s,options:[{label:"Trending Posts",value:"trending"},{label:"Related Posts",value:"related"}],onChange:e=>n({recommendationsType:e})}))),a().createElement(e,t))}),"withQueryLoopControls"))})();
  • atlas-search/trunk/build/recommendations-block/query-loop.php

    r3261003 r3264568  
    2121        $GLOBALS['rec_block'] = $block;
    2222
     23        if ( isset( $block['attrs']['query'] ) ) {
     24            $block['attrs']['query']['postsPerPage'] = (int) ( $block['attrs']['postLimit'] ?? 5 );
     25        }
     26
    2327        add_filter(
    2428            'query_loop_block_query_vars',
     
    3741    do_action( 'qm/debug', $block['attrs'] );
    3842
    39     $post_limit           = (int) ( $block['attrs']['postLimit'] ?? 6 );
     43    $post_limit           = (int) ( $block['attrs']['postLimit'] ?? 5 );
    4044    $recommendations_type = (string) ( $block['attrs']['recommendationsType'] ?? 'trending' );
    4145    if ( 'trending' === $recommendations_type ) {
     
    5559    }
    5660
     61    if ( empty( $popular_ids ) ) {
     62        return $query;
     63    }
     64
    5765    $query['post__in'] = $popular_ids;
    58     $query['orderby']  = 'post__in';
    5966
    60     // Remove the filter after it has been applied to avoid affecting other query loops.
     67    $query['orderby']        = 'post__in';
     68    $query['posts_per_page'] = $post_limit;
     69
    6170    remove_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\modify_query_vars' );
    6271
     
    9099function get_trending_posts( $count ) {
    91100    $vars = array( 'count' => $count );
    92     $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars );
    93     $docs = $data['data']['recommendations']['trendingDocuments'];
    94     return format_docs_as_ids( $docs );
     101
     102    try {
     103        $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars );
     104
     105        if ( isset( $data['errors'] ) ) {
     106            return array();
     107        }
     108
     109        $docs = $data['data']['recommendations']['trendingDocuments'] ?? array();
     110
     111        return format_docs_as_ids( $docs );
     112
     113    } catch ( \Exception $e ) {
     114        return array();
     115    }
    95116}
    96117
     118
     119
    97120function format_docs_as_ids( $docs ) {
     121    if ( empty( $docs ) ) {
     122        return array();
     123    }
    98124    $ids = array();
    99125
     
    111137        'doc_id' => $post_type . ':' . $post_id,
    112138    );
    113     $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars );
    114     $docs = $data['data']['recommendations']['relatedDocuments'];
    115     return format_docs_as_ids( $docs );
     139
     140    try {
     141        $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars );
     142
     143        $docs = $data['data']['recommendations']['relatedDocuments'] ?? array();
     144        if ( isset( $data['errors'] ) ) {
     145            return array();
     146        }
     147
     148        return format_docs_as_ids( $docs );
     149
     150    } catch ( \Exception $e ) {
     151        return array();
     152    }
    116153}
  • atlas-search/trunk/helper/search/search.php

    r3239389 r3264568  
    294294         * Sometimes WP plugin developers calling with negative number expect to get all posts
    295295         */
    296         $posts_per_page = ( $posts_per_page < 0 ) ? 1000 : $posts_per_page;
    297         $query_offset   = $query->get( 'offset', false );
    298         $offset         = false !== $query_offset ? $query_offset : self::get_offset( $page_number, $posts_per_page );
    299         $filter         = $this->generate_filters( $post_types, $query, $excluded_post_types );
     296        $posts_per_page = ( $posts_per_page < 0 || $posts_per_page > 1000 ) ? 1000 : $posts_per_page;
     297        $query->set( 'posts_per_page', $posts_per_page );
     298        $query_offset = $query->get( 'offset', false );
     299        $offset       = false !== $query_offset ? $query_offset : self::get_offset( $page_number, $posts_per_page );
     300        $filter       = $this->generate_filters( $post_types, $query, $excluded_post_types );
    300301
    301302        if ( 0 == $posts_per_page ) {
  • atlas-search/trunk/src/blocks/recommendations-block/index.js

    r3247243 r3264568  
    2323    query: {
    2424      postType: 'post',
    25       perPage: 3,
    26       pages: 1,
    27       order: 'asc',
    28       orderBy: 'title',
    2925      offset: 0,
    3026      exclude: [],
    3127      inherit: false,
     28      perPage: 5,
     29      sticky: 'exclude',
    3230    },
    3331    postLimit: 5,
    3432    recommendationsType: 'trending',
    3533  },
     34  allowedControls: ['postType', 'sticky', 'taxQuery'],
    3635  scope: ['inserter'],
    3736  isActive: ['namespace'],
     
    9796                label={__('Count', 'wpengine-smart-search')}
    9897                value={postLimit}
    99                 onChange={(newPostLimit) =>
    100                   setAttributes({ postLimit: newPostLimit })
    101                 }
     98                onChange={(newPostLimit) => {
     99                  setAttributes({
     100                    postLimit: newPostLimit,
     101                    query: { ...attributes.query, perPage: newPostLimit },
     102                  });
     103                }}
    102104                min={1}
    103105                max={20}
  • atlas-search/trunk/src/blocks/recommendations-block/index.test.js

    r3247243 r3264568  
    6767    });
    6868
    69     expect(setAttributes).toHaveBeenCalledWith({ postLimit: '10' });
     69    expect(setAttributes).toHaveBeenCalledWith({
     70      postLimit: '10',
     71      query: { perPage: '10' },
     72    });
    7073  });
    7174
  • atlas-search/trunk/src/blocks/recommendations-block/query-loop.php

    r3261003 r3264568  
    2121        $GLOBALS['rec_block'] = $block;
    2222
     23        if ( isset( $block['attrs']['query'] ) ) {
     24            $block['attrs']['query']['postsPerPage'] = (int) ( $block['attrs']['postLimit'] ?? 5 );
     25        }
     26
    2327        add_filter(
    2428            'query_loop_block_query_vars',
     
    3741    do_action( 'qm/debug', $block['attrs'] );
    3842
    39     $post_limit           = (int) ( $block['attrs']['postLimit'] ?? 6 );
     43    $post_limit           = (int) ( $block['attrs']['postLimit'] ?? 5 );
    4044    $recommendations_type = (string) ( $block['attrs']['recommendationsType'] ?? 'trending' );
    4145    if ( 'trending' === $recommendations_type ) {
     
    5559    }
    5660
     61    if ( empty( $popular_ids ) ) {
     62        return $query;
     63    }
     64
    5765    $query['post__in'] = $popular_ids;
    58     $query['orderby']  = 'post__in';
    5966
    60     // Remove the filter after it has been applied to avoid affecting other query loops.
     67    $query['orderby']        = 'post__in';
     68    $query['posts_per_page'] = $post_limit;
     69
    6170    remove_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\modify_query_vars' );
    6271
     
    9099function get_trending_posts( $count ) {
    91100    $vars = array( 'count' => $count );
    92     $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars );
    93     $docs = $data['data']['recommendations']['trendingDocuments'];
    94     return format_docs_as_ids( $docs );
     101
     102    try {
     103        $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars );
     104
     105        if ( isset( $data['errors'] ) ) {
     106            return array();
     107        }
     108
     109        $docs = $data['data']['recommendations']['trendingDocuments'] ?? array();
     110
     111        return format_docs_as_ids( $docs );
     112
     113    } catch ( \Exception $e ) {
     114        return array();
     115    }
    95116}
    96117
     118
     119
    97120function format_docs_as_ids( $docs ) {
     121    if ( empty( $docs ) ) {
     122        return array();
     123    }
    98124    $ids = array();
    99125
     
    111137        'doc_id' => $post_type . ':' . $post_id,
    112138    );
    113     $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars );
    114     $docs = $data['data']['recommendations']['relatedDocuments'];
    115     return format_docs_as_ids( $docs );
     139
     140    try {
     141        $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars );
     142
     143        $docs = $data['data']['recommendations']['relatedDocuments'] ?? array();
     144        if ( isset( $data['errors'] ) ) {
     145            return array();
     146        }
     147
     148        return format_docs_as_ids( $docs );
     149
     150    } catch ( \Exception $e ) {
     151        return array();
     152    }
    116153}
Note: See TracChangeset for help on using the changeset viewer.