Plugin Directory

Changeset 893715


Ignore:
Timestamp:
04/15/2014 04:21:26 PM (12 years ago)
Author:
dtelepathy
Message:

Increment version to 1.2.0; Modify AJAX end-point to respond to JSONP requests with a _REQUESTcallback? parameter; Restructure post_types structure in AJAX end-point response to respond with a key/value pair of name and label

Location:
filament/branches/jsonp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • filament/branches/jsonp/filament.php

    r887038 r893715  
    44Plugin URI: http://filament.io/
    55Description: Install & manage all your Web apps from a single place. Connect your website to Filament with this plugin, and never bug your developers again!
    6 Version: 1.1.0
     6Version: 1.2.0
    77Author: dtelepathy
    88Author URI: http://www.dtelepathy.com/
     
    3131    var $slug = "filament";
    3232    var $menu_hooks = array();
    33     var $version = '1.1.0';
     33    var $version = '1.2.0';
    3434
    3535    /**
     
    129129     */
    130130    public function ajax_taxonomy_structure() {
    131         header( 'Content-type: application/json' );
     131        $header = "application/json";
     132       
     133        if( isset( $_REQUEST['callback'] ) ) {
     134            $callback = preg_replace( "/([^A-Za-z0-9_\$\.]+)/", "", $_REQUEST['callback'] );
     135            $header =  "application/javascript";
     136        }
     137
     138        header( 'Content-type: ' . $header );
    132139
    133140        $structure = array(
     
    139146        $post_types = wp_cache_get( 'post_types', $this->slug );
    140147        if( !$post_types ) {
    141             $post_types = get_post_types( array( 'public' => true ) );
     148            $post_types = array();
     149            $post_type_slugs = get_post_types( array( 'public' => true ) );
     150           
     151            foreach( $post_type_slugs as $post_type_slug ) $post_types[] = get_post_type_object( $post_type_slug );
     152
    142153            wp_cache_set( 'post_types', $post_types, $this->slug, 3600 );
    143154        }
     
    155166        }
    156167
    157         $structure['post_types'] = array_values( $post_types );
    158         foreach( $categories as $category ) $structure['categories'][] = $category->slug;
    159         foreach( $tags as $tag ) $structure['tags'][] = $tag->slug;
     168        foreach( $post_types as $post_type ) $structure['post_types'][$post_type->name] = $post_type->label;
     169        foreach( $categories as $category ) $structure['categories'][$category->slug] = $category->name;
     170        foreach( $tags as $tag ) $structure['tags'][$tag->slug] = $tag->name;
    160171       
    161         exit( json_encode( $structure ) );
     172        $data = json_encode( $structure );
     173
     174        if( isset( $callback ) && !empty( $callback ) ) {
     175            $data = "$callback($data)";
     176        }
     177
     178        exit( $data );
    162179    }
    163180
  • filament/branches/jsonp/readme.txt

    r887038 r893715  
    4747
    4848== Changelog ==
     49= 1.2.0 =
     50* Modify AJAX end-point to respond to JSONP requests with a _REQUEST['callback'] parameter
     51* Restructure post_types structure in AJAX end-point response to respond with a key/value pair of name and label
     52
    4953= 1.1.0 =
    5054* Add save messaging to admin view
Note: See TracChangeset for help on using the changeset viewer.