Changeset 1231566
- Timestamp:
- 08/26/2015 11:41:16 PM (11 years ago)
- Location:
- angularjs-for-wp/trunk
- Files:
-
- 8 edited
-
angularjs-templates/list-detail.html (modified) (1 diff)
-
angularjs-templates/new-post.html (modified) (1 diff)
-
angularjs-templates/post-content.html (modified) (1 diff)
-
angularjs-templates/single-detail.html (modified) (1 diff)
-
includes/shortcodes.php (modified) (1 diff)
-
js/angular-posts-directives.js (modified) (5 diffs)
-
plugin.php (modified) (6 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
angularjs-for-wp/trunk/angularjs-templates/list-detail.html
r1149615 r1231566 35 35 --> 36 36 <article> 37 <h2>{{post.title }}</h2>38 <div ng-bind-html="post.content | sanitize"></div>37 <h2>{{post.title.rendered}}</h2> 38 <div ng-bind-html="post.content.rendered | sanitize"></div> 39 39 <a href="{{post.link}}">Read More...</a> 40 40 <hr /> -
angularjs-for-wp/trunk/angularjs-templates/new-post.html
r1089568 r1231566 9 9 <label>{{tax.name}}</label><br/> 10 10 <select ng-model="chosenTax[tax.slug]" data-tax="{{tax.slug}}" class="form-control" multiple="multiple"> 11 <option ng-repeat="term in tax.terms" value="{{term. ID}}">{{term.name}}</option>11 <option ng-repeat="term in tax.terms" value="{{term.id}}">{{term.name}}</option> 12 12 </select> 13 13 </div> -
angularjs-for-wp/trunk/angularjs-templates/post-content.html
r1149626 r1231566 2 2 This is for the content that loads from the meta box 3 3 --> 4 <div ng-bind-html='content | sanitize'></div>4 <div ng-bind-html='content.rendered | sanitize'></div> -
angularjs-for-wp/trunk/angularjs-templates/single-detail.html
r1149615 r1231566 35 35 --> 36 36 <article> 37 <h2>{{post.title }}</h2>38 <div ng-bind-html="post.content | sanitize"></div>37 <h2>{{post.title.rendered}}</h2> 38 <div ng-bind-html="post.content.rendered | sanitize"></div> 39 39 <a href="{{post.link}}">Read More...</a> 40 40 <hr /> -
angularjs-for-wp/trunk/includes/shortcodes.php
r1181507 r1231566 13 13 'search' => '', 14 14 'per_page' => '', 15 'page' => '', 15 16 ), $atts ); 16 17 -
angularjs-for-wp/trunk/js/angular-posts-directives.js
r1135719 r1231566 22 22 if(filters.length > 0){ 23 23 angular.forEach(filters, function(value, key){ 24 $scope.baseURL = $scope.baseURL + 'filter['+ value.filter + ']=' + value.value + '&'; 24 if( value.filter === 'posts_per_page' ){ 25 $scope.baseURL = $scope.baseURL + 'per_page=' + value.value + '&'; 26 } else if( value.filter == 'page' ) { 27 $scope.baseURL = $scope.baseURL + 'page=' + value.value + '&'; 28 } else { 29 $scope.baseURL = $scope.baseURL + 'filter['+ value.filter + ']=' + value.value + '&'; 30 } 25 31 }) 26 32 } … … 49 55 if($scope.search) { $scope.filters.push({'filter': 's', 'value': $scope.search}); } 50 56 if($scope.perPage) { $scope.filters.push({'filter': 'posts_per_page', 'value': $scope.perPage}); } 51 if($scope.page) { $scope.filters.push({'filter': 'p osts_per_page', 'value': $scope.page}); }57 if($scope.page) { $scope.filters.push({'filter': 'page', 'value': $scope.page}); } 52 58 53 59 $scope.getPosts($scope.filters, $scope.postType); … … 104 110 105 111 $scope.chosenTax = []; 106 if( !$scope.postType ) 112 if( !$scope.postType ) { 107 113 $scope.postType = 'post' 108 114 } 109 115 $http.get( wpAngularVars.base + '/taxonomies' ).then(function(res) { 110 116 $scope.taxonomies = []; 111 117 angular.forEach( res.data, function( value, key ) { 112 if( value.types.hasOwnProperty($scope.postType) && value.name !== 'Format' ) 113 $http.get( wpAngularVars.base + '/taxonomies/' + value.labels.name_admin_bar.toLowerCase() + '/terms' ).then(function(res){ 118 if( value.types.indexOf($scope.postType) > -1 && value.name !== 'Format' ) { 119 $http.get( wpAngularVars.base + '/terms/' + value.slug.toLowerCase() ).then(function(res){ 120 console.log(res); 114 121 value.terms = res.data; 115 122 $scope.taxonomies.push( value ); 116 123 }); 124 } 117 125 }); 118 126 … … 122 130 $scope.data = { 123 131 title: form.find('input[name="postTitle"]').val(), 124 content _raw: form.find('textarea[name="postContent"]').val(),132 content: form.find('textarea[name="postContent"]').val(), 125 133 status: 'publish', 126 type: $scope.postType,134 post_type: $scope.postType, 127 135 post_taxonomies: [] 128 136 } … … 130 138 if( jQuery(this).val() ) { 131 139 var tax = jQuery(this).data('tax'), 132 terms = jQuery(this).val(); 133 jQuery.each(terms, function( key, term ) { 134 $scope.data.post_taxonomies[term] = tax; 140 selected = jQuery(this).find(':selected'); 141 jQuery.each(selected, function( key, select ) { 142 var term = jQuery( select ).val(); 143 $scope.data.post_taxonomies[term] = tax 135 144 }); 136 145 } 137 146 }); 138 $http.post(wpAngularVars.base + '/posts/?_wp_json_nonce=' + wpAngularVars.nonce, $scope.data).then(function(res){ 147 var req = { 148 method: 'POST', 149 url: wpAngularVars.base + '/posts/', 150 headers: { 151 'X-WP-Nonce': wpAngularVars.nonce 152 }, 153 data: $scope.data 154 }; 155 156 if( $scope.postType && $scope.postType !== 'posts' ) { 157 req.url = wpAngularVars.base + '/' + $scope.postType; 158 } 159 160 $http(req).then(function(res){ 161 console.log(res); 139 162 if(res.data){ 140 163 // After Submit Function - redirect | clear | hide 141 if(!$scope.afterSubmit) { window.location = wpAngularVars.site + '/?p=' + res.data. ID; }164 if(!$scope.afterSubmit) { window.location = wpAngularVars.site + '/?p=' + res.data.id; } 142 165 if($scope.afterSubmit == 'redirect') { 143 166 if(!$scope.redirectURL) { 144 window.location = wpAngularVars.site + '/?p=' + res.data. ID;167 window.location = wpAngularVars.site + '/?p=' + res.data.id; 145 168 } else{ 146 169 window.location = $scope.redirectURL; -
angularjs-for-wp/trunk/plugin.php
r1181193 r1231566 4 4 * Plugin URI: http://www.roysivan.com/angularjs-for-wordpress 5 5 * Description: This plugin will allow you to easily load WordPress content client-side using AngularJS. JSON REST API required. 6 * Version: 2.0.16 * Version: 3.0.0 7 7 * Author: Roy Sivan 8 8 * Author URI: http://www.roysivan.com … … 17 17 18 18 class WordPressAngularJS { 19 function WordPressAngularJS(){ 20 global $wpdb; 19 20 function __init(){ 21 22 global $wpdb; 21 23 add_action( 'wp_enqueue_scripts', array( $this, 'angularScripts' ) ); 22 add_filter( 'json_insert_post', array( $this, 'post_add_tax' ), 10, 3 ); 24 add_filter( 'rest_api_init', array( $this, 'post_add_tax_register' ), 10, 3 ); 25 23 26 } 24 27 … … 63 66 $angularjs_for_wp_localize = array( 64 67 'site' => get_bloginfo('wpurl'), 65 'nonce' => wp_create_nonce( 'wp_ json' ),68 'nonce' => wp_create_nonce( 'wp_rest' ), 66 69 'template_directory' => $template_directory 67 70 ); … … 83 86 } 84 87 85 function post_add_tax( $post, $data, $update ) { 86 foreach( $data['post_taxonomies'] as $term => $tax ){ 87 wp_set_post_terms( $post['ID'], array( intval( $term ) ), $tax, true ); 88 } 88 function post_add_tax_register() { 89 90 91 $post_types = get_post_types( array( 'public' => true, 'exclude_from_search' => false ), 'names' ); 92 93 foreach( $post_types as $cpt ) { 94 if( $cpt === 'attachment' ) { continue; } 95 register_api_field( $cpt, 96 'post_taxonomies', 97 array( 98 'update_callback' => array( $this, 'post_add_tax' ), 99 'schema' => null, 100 ) 101 ); 102 } 103 104 } 105 106 function post_add_tax( $value, $object, $field_name ) { 107 //var_dump( $value ); 108 foreach( $value as $term => $tax ){ 109 wp_set_post_terms( $object->ID, array( intval( $term ) ), $tax, true ); 110 } 111 89 112 } 90 113 } … … 93 116 function angularjs_plugin_dep() { 94 117 if ( ! defined( 'REST_API_VERSION' ) ) { 95 function wpsd_admin_notice() {96 printf( '<div class="error"><p>%s</p></div>', __( 'Activate the WP REST API plugin. It97 is required.' ) );98 }99 118 add_action( 'admin_notices', 'angular_wpapi_error' ); 100 119 } … … 102 121 103 122 function angular_wpapi_error(){ 104 echo '<div class="error"><p><strong>JSON REST API</strong> must be installed and activated for the <strong>AngularJS for WP</strong> plugin to work properly - <a href="https://wordpress.org/plugins/ json-rest-api/" target="_blank">Install Plugin</a></p></div>';123 echo '<div class="error"><p><strong>JSON REST API</strong> must be installed and activated for the <strong>AngularJS for WP</strong> plugin to work properly - <a href="https://wordpress.org/plugins/rest-api/" target="_blank">Install Plugin</a></p></div>'; 105 124 } 106 125 107 126 add_action( 'admin_init', 'angularjs_plugin_dep', 99 ); 108 127 109 new WordPressAngularJS(); 128 /** LOAD PLUGIN **/ 129 130 $wpNG = new WordPressAngularJS(); 131 add_action( 'init', array( $wpNG, '__init' ), 1000 ); 132 133 134 110 135 ?> -
angularjs-for-wp/trunk/readme.txt
r1181507 r1231566 4 4 Tags: angularjs, angular js, angular, javascript, client side, single page application, mvc, client side framework 5 5 Requires at least: 3.9 6 Tested up to: 4. 2.27 Stable tag: 2.16 Tested up to: 4.3 7 Stable tag: 3.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 30 30 1. Log into your WordPress dashboard and add the new plugin via upload 31 31 1. Activate the plugin 32 1. Make sure you have the JSON REST API (WP-API)plugin also activated32 1. Make sure you have the JSON REST API v2 plugin also activated 33 33 1. View [documentation](http://www.roysivan.com/angularjs-for-wordpress) for how to utilize the directives 34 34 … … 79 79 = 2.1 = 80 80 * Adding in fix for AngularJS FireBase Chat Room plugin shortcode 81 82 = 3.0 = 83 * ONLY SUPPORTS JSON REST API V2
Note: See TracChangeset
for help on using the changeset viewer.