Plugin Directory

Changeset 1868361


Ignore:
Timestamp:
05/03/2018 09:21:09 PM (8 years ago)
Author:
rveitch
Message:

Updating plugin 3.1.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coschedule-by-todaymade/trunk/tm-scheduler.php

    r1856024 r1868361  
    33Plugin Name: CoSchedule
    44Description: Plan, organize, and execute every content marketing project in one place with CoSchedule, an all-in-one content marketing editorial calendar solution.
    5 Version: 3.0.5
     5Version: 3.1.0
    66Author: CoSchedule
    77Author URI: http://coschedule.com/
     
    2323        private $webhooks_url = "https://webhooks.coschedule.com";
    2424        private $app = "https://app.coschedule.com";
    25         private $assets = "https://d2lbmhk9kvi6z5.cloudfront.net";
    26         private $version = "3.0.5";
     25        private $assets = "https://assets.coschedule.com";
     26        private $version = "3.1.0";
    2727        private $build;
    2828        private $connected = false;
     
    4848
    4949            // Load variables
    50             $this->build                  = intval( "77" );
     50            $this->build                  = intval( "78" );
    5151            $this->token                  = get_option( 'tm_coschedule_token' );
    5252            $this->calendar_id            = get_option( 'tm_coschedule_calendar_id' );
     
    172172            // Custom Slug Fix, replace data
    173173            add_filter( 'wp_insert_post_data', array( $this, 'fix_custom_slug_after' ), 20 );
     174
     175            // Open Graph Previews
     176            add_filter( 'posts_results', array( $this, 'set_post_visibility' ), 10, 2 );
    174177        }
    175178
     
    731734        }
    732735
     736        /**
     737         * Retrieves a post with HTML
     738         *
     739         * @param $data_args
     740         */
     741        public function tm_aj_get_full_html_post( $data_args ) {
     742            try {
     743                if ( isset( $data_args['post_id'] ) ) {
     744                    $post_id = $data_args['post_id'];
     745                } else {
     746                    throw new Exception( 'Invalid API call. Missing argument(s).' );
     747                }
     748
     749                $nonce = wp_create_nonce( 'coschedule_preview_' . $this->token .' _post_id-' . $post_id );
     750                wp_safe_redirect( add_query_arg( 'cos_preview', $nonce, get_permalink( $post_id ) ), 301 );
     751                exit;
     752            } catch ( Exception $e ) {
     753                $data['error'] = $e->getMessage();
     754                $this->respond_json_and_die( $data );
     755            }
     756        }
     757
     758        public function set_post_visibility( $posts ) {
     759            remove_filter( 'posts_results', array( $this, 'set_post_visibility' ), 10 );
     760            if ( empty( $posts ) || is_user_logged_in() || ! $this->is_preview_valid($posts) ) {
     761                return $posts;
     762            }
     763
     764            // Set in-memory status to 'publish' to enable the preview for this single request. This does not publish the post.
     765            $posts[0]->post_status = 'publish';
     766
     767            // Disable comments and pings for this post while previewing.
     768            add_filter( 'comments_open', '__return_false' );
     769            add_filter( 'pings_open', '__return_false' );
     770
     771            return $posts;
     772        }
     773
     774        public function is_preview_valid($posts) {
     775            if ( empty( $_GET[ 'cos_preview' ] ) || empty( $posts ) ) {
     776                return false;
     777            }
     778
     779            return wp_verify_nonce( $_GET[ 'cos_preview' ], 'coschedule_preview_' . $this->token .' _post_id-' . $posts[0]->ID );
     780        }
    733781
    734782        /**
     
    9851033                    'tm_aj_import_post',
    9861034                    'tm_aj_get_html_post',
     1035                    'tm_aj_get_full_html_post',
    9871036                );
    9881037
Note: See TracChangeset for help on using the changeset viewer.