Plugin Directory

Changeset 1231566


Ignore:
Timestamp:
08/26/2015 11:41:16 PM (11 years ago)
Author:
guavaworks
Message:

v3 - upgrading to JSON rest api v2 requirement.

Location:
angularjs-for-wp/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • angularjs-for-wp/trunk/angularjs-templates/list-detail.html

    r1149615 r1231566  
    3535-->
    3636<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>
    3939    <a href="{{post.link}}">Read More...</a>
    4040    <hr />
  • angularjs-for-wp/trunk/angularjs-templates/new-post.html

    r1089568 r1231566  
    99    <label>{{tax.name}}</label><br/>
    1010    <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>
    1212    </select>
    1313</div>
  • angularjs-for-wp/trunk/angularjs-templates/post-content.html

    r1149626 r1231566  
    22This is for the content that loads from the meta box
    33-->
    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  
    3535-->
    3636<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>
    3939    <a href="{{post.link}}">Read More...</a>
    4040    <hr />
  • angularjs-for-wp/trunk/includes/shortcodes.php

    r1181507 r1231566  
    1313        'search' => '',
    1414        'per_page' => '',
     15        'page' => '',
    1516    ), $atts );
    1617   
  • angularjs-for-wp/trunk/js/angular-posts-directives.js

    r1135719 r1231566  
    2222                if(filters.length > 0){
    2323                    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                        }
    2531                    })
    2632                }
     
    4955            if($scope.search) { $scope.filters.push({'filter': 's', 'value': $scope.search}); }
    5056            if($scope.perPage) { $scope.filters.push({'filter': 'posts_per_page', 'value': $scope.perPage}); }
    51             if($scope.page) { $scope.filters.push({'filter': 'posts_per_page', 'value': $scope.page}); }   
     57            if($scope.page) { $scope.filters.push({'filter': 'page', 'value': $scope.page}); } 
    5258           
    5359            $scope.getPosts($scope.filters, $scope.postType);
     
    104110           
    105111            $scope.chosenTax = [];
    106             if( !$scope.postType )
     112            if( !$scope.postType ) {
    107113                $scope.postType = 'post'
    108                    
     114            }
    109115            $http.get( wpAngularVars.base + '/taxonomies' ).then(function(res) {
    110116                $scope.taxonomies = [];
    111117                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);
    114121                            value.terms = res.data;
    115122                            $scope.taxonomies.push( value );
    116123                        });
     124                    }
    117125                });
    118126               
     
    122130                $scope.data = {
    123131                    title: form.find('input[name="postTitle"]').val(),
    124                     content_raw: form.find('textarea[name="postContent"]').val(),
     132                    content: form.find('textarea[name="postContent"]').val(),
    125133                    status: 'publish',
    126                     type: $scope.postType,
     134                    post_type: $scope.postType,
    127135                    post_taxonomies: []
    128136                }
     
    130138                    if( jQuery(this).val() ) {
    131139                        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
    135144                        });
    136145                    }
    137146                });
    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);
    139162                    if(res.data){
    140163                        // 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; }
    142165                        if($scope.afterSubmit == 'redirect') { 
    143166                            if(!$scope.redirectURL) {
    144                                 window.location = wpAngularVars.site + '/?p=' + res.data.ID;
     167                                window.location = wpAngularVars.site + '/?p=' + res.data.id;
    145168                            } else{
    146169                                window.location = $scope.redirectURL;
  • angularjs-for-wp/trunk/plugin.php

    r1181193 r1231566  
    44 * Plugin URI: http://www.roysivan.com/angularjs-for-wordpress
    55 * Description: This plugin will allow you to easily load WordPress content client-side using AngularJS. JSON REST API required.
    6  * Version: 2.0.1
     6 * Version: 3.0.0
    77 * Author: Roy Sivan
    88 * Author URI: http://www.roysivan.com
     
    1717
    1818class WordPressAngularJS {
    19     function WordPressAngularJS(){
    20         global $wpdb;
     19   
     20    function __init(){
     21       
     22        global $wpdb;       
    2123        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       
    2326    }
    2427
     
    6366        $angularjs_for_wp_localize = array(
    6467            'site' => get_bloginfo('wpurl'),
    65             'nonce' => wp_create_nonce( 'wp_json' ),
     68            'nonce' => wp_create_nonce( 'wp_rest' ),
    6669            'template_directory' => $template_directory
    6770        );
     
    8386    }
    8487   
    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       
    89112    }
    90113}
     
    93116function angularjs_plugin_dep() {
    94117    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.  It
    97             is required.' ) );
    98         }
    99118        add_action( 'admin_notices', 'angular_wpapi_error' );
    100119    }
     
    102121
    103122function 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>';
    105124}
    106125
    107126add_action( 'admin_init', 'angularjs_plugin_dep', 99 );
    108127
    109 new WordPressAngularJS();
     128/** LOAD PLUGIN **/
     129
     130$wpNG = new WordPressAngularJS();
     131add_action( 'init', array( $wpNG, '__init' ), 1000 );
     132
     133
     134
    110135?>
  • angularjs-for-wp/trunk/readme.txt

    r1181507 r1231566  
    44Tags: angularjs, angular js, angular, javascript, client side, single page application, mvc, client side framework
    55Requires at least: 3.9
    6 Tested up to: 4.2.2
    7 Stable tag: 2.1
     6Tested up to: 4.3
     7Stable tag: 3.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    30301. Log into your WordPress dashboard and add the new plugin via upload
    31311. Activate the plugin
    32 1. Make sure you have the JSON REST API (WP-API) plugin also activated
     321. Make sure you have the JSON REST API v2 plugin also activated
    33331. View [documentation](http://www.roysivan.com/angularjs-for-wordpress) for how to utilize the directives
    3434
     
    7979= 2.1 =
    8080* 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.