Changeset 2000668
- Timestamp:
- 12/23/2018 05:41:38 PM (7 years ago)
- Location:
- wp-primary-category
- Files:
-
- 25 added
- 5 edited
-
tags/1.1.0 (added)
-
tags/1.1.0/.editorconfig (added)
-
tags/1.1.0/assets (added)
-
tags/1.1.0/assets/css (added)
-
tags/1.1.0/assets/css/admin.css (added)
-
tags/1.1.0/assets/js (added)
-
tags/1.1.0/assets/js/admin.js (added)
-
tags/1.1.0/includes (added)
-
tags/1.1.0/includes/classes (added)
-
tags/1.1.0/includes/classes/class-wp-primary-category-admin.php (added)
-
tags/1.1.0/includes/classes/class-wp-primary-category-rest-api.php (added)
-
tags/1.1.0/includes/classes/class-wp-primary-category-settings.php (added)
-
tags/1.1.0/includes/classes/class-wp-primary-category-shortcode.php (added)
-
tags/1.1.0/includes/classes/class-wp-primary-category.php (added)
-
tags/1.1.0/includes/functions.php (added)
-
tags/1.1.0/includes/views (added)
-
tags/1.1.0/includes/views/admin (added)
-
tags/1.1.0/includes/views/admin/html-inputs.php (added)
-
tags/1.1.0/includes/views/admin/html-settings.php (added)
-
tags/1.1.0/includes/views/admin/html-templates.php (added)
-
tags/1.1.0/phpcs.xml (added)
-
tags/1.1.0/plugin.php (added)
-
tags/1.1.0/readme.md (added)
-
tags/1.1.0/readme.txt (added)
-
trunk/includes/classes/class-wp-primary-category-rest-api.php (added)
-
trunk/includes/classes/class-wp-primary-category.php (modified) (2 diffs)
-
trunk/includes/functions.php (modified) (1 diff)
-
trunk/plugin.php (modified) (1 diff)
-
trunk/readme.md (modified) (4 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-primary-category/trunk/includes/classes/class-wp-primary-category.php
r1994274 r2000668 16 16 add_action( 'wp_loaded', array( 'WP_Primary_Category_Settings', 'init' ) ); 17 17 add_action( 'init', array( 'WP_Primary_Category_Shortcode', 'init' ) ); 18 18 add_action( 'rest_api_init', array( 'WP_Primary_Category_REST_API', 'init' ) ); 19 19 } 20 20 … … 23 23 require_once WP_PC_PLUGIN_PATH . 'includes/classes/class-wp-primary-category-settings.php'; 24 24 require_once WP_PC_PLUGIN_PATH . 'includes/classes/class-wp-primary-category-shortcode.php'; 25 require_once WP_PC_PLUGIN_PATH . 'includes/classes/class-wp-primary-category-rest-api.php'; 25 26 require_once WP_PC_PLUGIN_PATH . 'includes/functions.php'; 27 } 28 29 public static function get_primary_categories( $post = null, $output = OBJECT ) { 30 $post_id = self::_ge_post_id( $post ); 31 32 if ( ! $post_id ) { 33 return false; 34 } 35 36 $post_type = get_post_type( $post_id ); 37 $taxonomies = WP_Primary_Category_Settings::get_option( $post_type ); 38 39 $data = array(); 40 if ( $taxonomies ) { 41 foreach ( $taxonomies as $taxonomy ) { 42 $category = get_primary_category( $taxonomy, $post_id, $output ); 43 if ( $category ) { 44 $data[ $taxonomy ] = $category; 45 } 46 } 47 } 48 49 return $data; 26 50 } 27 51 -
wp-primary-category/trunk/includes/functions.php
r1994274 r2000668 3 3 if ( ! defined( 'ABSPATH' ) ) { 4 4 exit; 5 } 6 7 if ( ! function_exists( 'get_primary_categories' ) ) { 8 function get_primary_categories( $post = null, $output = OBJECT ) { 9 return WP_Primary_Category::get_primary_categories( $post, $output ); 10 } 5 11 } 6 12 -
wp-primary-category/trunk/plugin.php
r2000124 r2000668 5 5 * Author: Aires Gonçalves 6 6 * Author URI: http://github.com/airesvsg 7 * Version: 1. 0.17 * Version: 1.1.0 8 8 * Plugin URI: http://github.com/airesvsg/wp-primary-category 9 9 */ -
wp-primary-category/trunk/readme.md
r1994274 r2000668 13 13 - [Shortcode](#shortcode) 14 14 - [WP_Query](#wp_query) 15 - [REST API](#rest-api) 15 16 - [To Do](#to-do) 16 17 … … 52 53 | Name | Argument(s) | 53 54 |------|-------------| 55 | get_primary_categories | mixed ( int, WP_Post, NULL ) **$post**<br>*required*<br>--<br>string **$output**<br>*default value:* OBJECT<br>*others values:* OBJECT, ARRAY_A, ARRAY_N or "ID"<br>*optional* | 54 56 | get_primary_category | mixed ( int, WP_Term, object, string ) **$taxonomy**<br>*required*<br>--<br>mixed ( int, WP_Post, NULL ) **$post**<br>*default value:* NULL<br>*optional*<br>--<br>string **$output**<br>*default value:* OBJECT<br>*others values:* OBJECT, ARRAY_A, ARRAY_N or "ID"<br>*optional* | 55 57 | the_primary_category | mixed ( int, WP_Term, object, string ) **$taxonomy**<br>*required*<br>--<br>mixed ( int, WP_Post, NULL ) **$post**<br>*default value:* NULL<br>*optional*<br>--<br>string **$output**<br>*default value:* "link"<br>*others values:* "name"<br>*optional*--<br>string **$echo**<br>*default value:* true<br>*optional* | … … 94 96 | wp_primary_category_taxonomies | mixed ( array, boolean ) **$taxonomies** | 95 97 | wp_primary_category_html | string **$html**<br>mixed ( int, WP_Term, object, string ) **$taxonomy**<br>mixed ( int, WP_Post, NULL ) **$post**<br>string **$output** | 98 | wp_primary_category_rest_api_output | string ( OBJECT, ARRAY_A, ARRAY_N or "ID" ) **$output**<br> array **$request** | 99 | wp_primary_category_rest_api_data | array **$data**<br> array **$request** | 96 100 97 101 **How to use the filters?** … … 165 169 https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters 166 170 171 REST API 172 ==== 173 174 **Endpoint**: 175 `/wp-json/wp/v2/posts/1` 176 177 **Default answer:** 178 ```JSON 179 { 180 "id": 1, 181 "title": { 182 "rendered": "Hello world!" 183 }, 184 ... 185 "primary_categories": { 186 "category": 1, 187 "genre": 2 188 }, 189 ... 190 } 191 ``` 192 193 **Use the filter below to change the answer:** 194 ```PHP 195 add_filter( 'wp_primary_category_rest_api_data', function( $data ) { 196 if ( isset( $data['genre'] ) ) { 197 unset( $data['genre'] ); 198 } 199 200 return $data; 201 } ); 202 ``` 203 204 **The new answer:** 205 ```JSON 206 { 207 "id": 1, 208 "title": { 209 "rendered": "Hello world!" 210 }, 211 ... 212 "primary_categories": { 213 "category": 1 214 }, 215 ... 216 } 217 ``` 218 219 **Use the filter below to change the output:** 220 ```PHP 221 add_filter( 'wp_primary_category_rest_api_output', function() { 222 return OBJECT; // OBJECT, ARRAY_A, ARRAY_N or 'ID' 223 } ); 224 ``` 225 226 **The new answer:** 227 ```JSON 228 { 229 "id": 1, 230 "title": { 231 "rendered": "Hello world!" 232 }, 233 ... 234 "primary_categories": { 235 "category": { 236 "term_id": 1, 237 "name": "My category", 238 "slug": "my-category", 239 "term_group": 0, 240 "term_taxonomy_id": 2, 241 "taxonomy": "category", 242 "description": "", 243 "parent": 0, 244 "count": 1, 245 "filter": "raw" 246 } 247 }, 248 ... 249 } 250 ``` 251 167 252 To Do 168 253 ==== -
wp-primary-category/trunk/readme.txt
r2000124 r2000668 5 5 Requires at least: 4.6 6 6 Tested up to: 4.9.8 7 Stable tag: 1. 0.17 Stable tag: 1.1.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 22 22 == Changelog == 23 23 24 = 1.1.0 = 25 adding support to REST API 26 24 27 = 1.0.1 = 25 28 bugfix imposible to remove primary category once it has been set - Thanks to Mirko
Note: See TracChangeset
for help on using the changeset viewer.