PluginProbe
Filter Everything — WordPress & WooCommerce Filters / trunk
Filter Everything — WordPress & WooCommerce Filters vtrunk
1.9.6 1.9.5 1.9.4 1.9.3 1.9.2.2 1.9.2.1 trunk 1.2.1 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.1 1.4.4 1.4.5 1.4.8 1.4.9 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 All 51 releases
filter-everything / src / wpc-api.php

wpc-api.php in Filter Everything — WordPress & WooCommerce Filters trunk, at src/wpc-api.php

112 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined('ABSPATH') ) {
4 exit;
5 }
6
7 // SEO API
8 /**
9 * @param string $key title|description|h1|text
10 * @return string|false Needed seo data
11 */
12 function flrt_get_seo_data($key = 'title' ){
13 if( ! did_action('wp') ){
14 _doing_it_wrong(
15 'flrt_get_seo_data',
16 sprintf(
17 /* translators: %s: rest_api_init */
18 esc_html__( 'Please, do not call the "%s" function before the "wp" action', 'filter-everything' ),
19 'flrt_get_seo_data'
20 ),
21 '4.6'
22 );
23 return false;
24 }
25
26 $possibleValues = array(
27 'title' => 'seoTitle',
28 'description' => 'metaDescription',
29 'h1' => 'h1',
30 'text' => 'seoDescription',
31 );
32
33 if( in_array( $key, array_keys($possibleValues), true ) ){
34 $seoFrontend = \FilterEverything\Filter\Container::instance()->getSeoFrontendService();
35 return $seoFrontend->get( $possibleValues[$key] );
36 }
37
38 return false;
39 }
40
41 // Posts found quantity
42 /**
43 * @return int|null number of posts found
44 */
45 function flrt_posts_found_quantity( $setid, $all = false )
46 {
47 $wpManager = \FilterEverything\Filter\Container::instance()->getWpManager();
48 $em = \FilterEverything\Filter\Container::instance()->getEntityManager();
49
50 $count = NULL;
51
52 if( $wpManager->getQueryVar('wpc_is_filter_request' ) ){
53
54 $set_filter_keys = array_flip( $em->getSetFilterKeys( array( $setid ) ) );
55 $queried_keys = [];
56
57 foreach ( $wpManager->getQueryVar('queried_values') as $queried_value ){
58 $key = $queried_value['entity'].'#'.$queried_value['e_name'];
59 $queried_keys[ $key ] = true;
60 }
61
62 if( ! empty( array_intersect_key( $queried_keys, $set_filter_keys ) ) ){
63 $count = count( $em->getAlreadyFilteredPostIds( $setid ) );
64 }else if( $all ) {
65 $count = count( $em->getAlreadyFilteredPostIds( $setid ) );
66 }
67
68 } else if ( $all ){
69 $count = count( $em->getAlreadyFilteredPostIds( $setid ) );
70 }
71
72 return $count;
73 }
74
75 // Selected filter chips
76 /**
77 * @param bool $include_reset - include Reset button term or not
78 * @return array|false - selected terms
79 */
80 function flrt_selected_filter_chips($include_reset = true )
81 {
82 $chipsObj = new FilterEverything\Filter\Chips($include_reset);
83 return $chipsObj->getChips();
84 }
85
86 // Selected filter terms
87 /**
88 * @return array|false all selected filters or false
89 */
90 function flrt_selected_filter_terms()
91 {
92 $wpManager = \FilterEverything\Filter\Container::instance()->getWpManager();
93 return $wpManager->getQueryVar('queried_values');
94 }
95
96 // Get all filters related with current page
97 /**
98 * @return array of all filters from the Filter Set
99 * related with current page
100 * or empty array if there are no filters
101 */
102 function flrt_get_page_related_filters(){
103 /**
104 * @todo add check to hook if
105 */
106 if( ! did_action( 'pre_get_posts' ) ) {
107 _doing_it_wrong( __FUNCTION__, esc_html__('This function should not be called before the pre_get_posts hook has fired.', 'filter-everything'), '1.7.16' );
108 } else{
109 $em = \FilterEverything\Filter\Container::instance()->getEntityManager();
110 return $em->getSetsRelatedFilters();
111 }
112 }