Plugin Directory

Changeset 3234465


Ignore:
Timestamp:
02/04/2025 07:28:54 AM (13 months ago)
Author:
jamesdlow
Message:

1.4.4

  • Add option to query by meta

1.4.3

  • Add optional API key authentication for WP JSON API
Location:
pageapp
Files:
18 added
2 edited

Legend:

Unmodified
Added
Removed
  • pageapp/trunk/pageapp.php

    r3168966 r3234465  
    44Plugin URI: https://wordpress.org/plugins/pageapp/
    55Description: Extensions to Wordpress wp-json for the PageApp API and mobile framework
    6 Version: 1.4.3
     6Version: 1.4.4
    77Author: PageApp
    88Author URI: https://www.pageapp.com
     
    4141    public static function plugin() {
    4242        return plugins_url(null,__FILE__);
     43    }
     44    public static function is_rest() {
     45        return defined('REST_REQUEST') && REST_REQUEST;
    4346    }
    4447
     
    6063        add_filter('lostpassword_redirect', array(static::class, 'lostpassword_redirect'));
    6164        add_filter('rest_pre_dispatch', array(static::class, 'rest_pre_dispatch'), 10, 3);
     65
     66        if (get_option('pageapp_metaquery') == '1') {
     67            add_filter('rest_post_query', array(static::class, 'filter_rest_meta_query'), 10, 2);
     68            add_filter('rest_page_query', array(static::class, 'filter_rest_meta_query'), 10, 2);
     69            add_filter('rest_attachment_query', array(static::class, 'filter_rest_meta_query'), 10, 2);
     70            add_filter('rest_post_tag_query', array(static::class, 'filter_rest_meta_query'), 10, 2);
     71            add_filter('rest_cateegory_query', array(static::class, 'filter_rest_meta_query'), 10, 2);
     72            add_filter('rest_user_query', array(static::class, 'filter_rest_meta_query'), 10, 2);
     73        }
     74        if (get_option('pageapp_addimages') == '1') {
     75            add_filter('rest_prepare_post_tag', array(static::class, 'rest_prepre_term'), 10, 3);
     76            add_filter('rest_prepare_category', array(static::class, 'rest_prepre_term'), 10, 3);
     77        }
     78    }
     79    public static function rest_prepre_term($response, $item, $request) {
     80        $attachment_id = get_term_meta($item->term_id, 'attachment_id', true);
     81        if ($attachment_id) {
     82            $response->data['featured_image_urls'] = self::get_attahment_urls(get_term_meta($item->term_id, 'attachment_id', true));
     83        }
     84        return $response;
    6285    }
    6386    public static function init() {
     
    7093            array('id'=>'pageapp_relevanssi', 'type'=>'boolean', 'title'=>'Enable Relevanssi'),
    7194            array('id'=>'pageapp_whitelist', 'type'=>'boolean', 'title'=>'Whitelist Post Meta'),
    72             array('id'=>'pageapp_addimages', 'type'=>'boolean', 'title'=>'Add Images to Posts'),
     95            array('id'=>'pageapp_addimages', 'type'=>'boolean', 'title'=>'Add Images to Posts/Pages/Terms'),
    7396            array('id'=>'pageapp_categories', 'type'=>'boolean', 'title'=>'Include Category Details'),
    7497            array('id'=>'pageapp_customposts', 'type'=>'boolean', 'title'=>'Include Custom Post Types'),
     98            array('id'=>'pageapp_metaquery', 'type'=>'boolean', 'title'=>'Enable Querying by Meta'),
    7599            array('id'=>'pageapp_apisettings', 'type'=>'title', 'title'=>'API Settings'),
    76100            array('id'=>'pageapp_restkey', 'type'=>'boolean', 'title'=>'WP JSON Key', 'description'=>'Require apikey on WP JSON API'),
     
    291315                    )
    292316                );
     317                //TODO: This doesn't seem to work
    293318                $taxonomies = get_object_taxonomies($post_type, 'objects');
    294319                foreach ($taxonomies as $name => $tax) {
     
    370395    }
    371396    public static function image_sizes($post_id, $post_type = null) {
    372         $featured_id = get_post_thumbnail_id($post_id);
     397        return self::get_attahment_urls(get_post_thumbnail_id($post_id));
     398    }
     399    public static function get_attahment_urls($featured_id) {
    373400        $sizes = wp_get_attachment_metadata($featured_id);
    374401        $size_data = array();
    375402        if (!empty($sizes['sizes'])) {
     403            $sizes['sizes']['full'] = [];
    376404            foreach ($sizes['sizes'] as $key => $size) {
    377405                $image_src = wp_get_attachment_image_src($featured_id, $key);
     
    442470        }
    443471        return $result;
     472    }
     473    public static function filter_rest_meta_query($args, $request = null) {
     474        $request = $_REQUEST;
     475        if (!empty($request['meta_key']) && !empty($request['meta_compare'])) {
     476            $meta_query = [
     477                [
     478                    'key'     => sanitize_text_field($request['meta_key']),
     479                    'compare' => sanitize_text_field($request['meta_compare']),
     480                ],
     481            ];
     482   
     483            if (!empty($request['meta_value'])) {
     484                $meta_query[0]['value'] = sanitize_text_field($request['meta_value']);
     485            }
     486   
     487            $args['meta_query'] = $meta_query;
     488        }
     489        return $args;
    444490    }
    445491
  • pageapp/trunk/readme.txt

    r3168966 r3234465  
    44Requires at least: 3.0
    55Tested up to: 6.5.4
    6 Stable tag: 1.4.3
     6Stable tag: 1.4.4
    77License: © 2024 Thireen32 Pty Ltd
    88Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=K6VKWB3HZB2T2&item_name=Donation%20to%20jameslow%2ecom&currency_code=USD&bn=PP%2dDonationsBF&charset=UTF%2d8
     
    2828
    2929== Changelog ==
     30
     31= 1.4.4 =
     32* Add option to query by meta
    3033
    3134= 1.4.3 =
Note: See TracChangeset for help on using the changeset viewer.