Plugin Directory

Changeset 1361838


Ignore:
Timestamp:
03/01/2016 03:11:53 PM (10 years ago)
Author:
pagefrog
Message:

adding override plugins option

Location:
pagefrog/trunk
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • pagefrog/trunk/README.txt

    r1359856 r1361838  
    224224
    225225== Changelog ==
     226= 1.0.7.2 =
     227*Release Date - February 29, 2016*
     228
     229* Add feature to turn off plugins that might raise AMP errors
     230
    226231= 1.0.7.1 =
    227 *Release Date - February 27, 2017*
     232*Release Date - February 27, 2016*
    228233
    229234* Explanation text to help enabling articles
  • pagefrog/trunk/admin/class-pagefrog-admin.php

    r1359856 r1361838  
    285285            add_action( 'template_redirect', array($this, 'really_handle_preview'));
    286286        }
     287    }
     288
     289    /**
     290     * Maybe unattach plugins for this request (if it is amp and the user requested that).
     291     *
     292     * @since   1.0.7.2
     293     */
     294    public function maybe_disable_plugins( ) {
     295        global $wp_filter;
     296        /*
     297         * The $wp_filter variable holds a list of hooks in the format
     298         * $wp_filter[hook_name][priority_integer][name_of_callable] = array(
     299         *      function => 'name_of_callable' string, or array with [0] pointing to an object and
     300         *                     [1] pointing to the name of the function to be called on that object,
     301         *      accepted_args => number of accepted args (int)
     302         * )
     303         *
     304         * Note that $wp_filter does not differentiate between actions and filters, so we can just call
     305         * remove_filter for both.
     306         */
     307
     308
     309        // check if we are on an amp endpoint
     310        if (
     311            ( defined( 'AMP_QUERY_VAR' ) && false !== get_query_var( AMP_QUERY_VAR, false ) ) ||
     312            ( isset( $GLOBALS['PRETEND_AMP_WP_IS_INSTALLED'] ) && $GLOBALS['PRETEND_AMP_WP_IS_INSTALLED'] == true && isset( $GLOBALS['PRETEND_AMP_WP_IS_ACTIVATED'] ) && $GLOBALS['PRETEND_AMP_WP_IS_ACTIVATED'] === true )
     313        ) {
     314            // check if we should remove plugins from amp input
     315            $new_posts = new PageFrog_NewPostSettings_Storage();
     316            if ( ! $new_posts->get_amp_disable_other_plugins_bool() ) {
     317                // we aren't supposed to remove other plugins
     318                return array();
     319            }
     320
     321            // if we reach here, we need to remove the plugins
     322            $to_remove = array();
     323            // iterate over all of the hooks, recording which ones we think maybe we should remove
     324            foreach ( $wp_filter as $hook => $hook_group ) {
     325                foreach ( $hook_group as $priority => $priority_group ) {
     326                    foreach ( $priority_group as $callable => $callable_group ) {
     327                        try {
     328                            if ( is_array( $callable_group['function'] ) ) {
     329                                // it looks like we have a class method that we are analyzing
     330                                // get hte file path to the function
     331                                if ( is_string( $callable_group['function'][0] ) ) {
     332                                    // it's a static method
     333                                    $refl = new ReflectionMethod( $callable_group['function'][0] . '::' . $callable_group['function'][1] );
     334                                } else {
     335                                    // it's an instance method
     336                                    $refl = new ReflectionClass( get_class( $callable_group['function'][0] ) );
     337                                }
     338                            } else {
     339                                // it looks like we have a simple function that we are analyzing
     340                                // get the file path to the function
     341                                $refl = new ReflectionFunction( $callable_group['function'] );
     342                            }
     343
     344                            // get the file path
     345                            $file_path = $refl->getFileName();
     346
     347                            // check if the function is inside of the plugins directory
     348                            if (
     349                                PageFrog_Utils::starts_with( $file_path, WP_PLUGIN_DIR )
     350                            ) {
     351
     352                                // check if the function is not part of pagefrog and not part of the amp-wp plugins
     353                                if (
     354                                    ! PageFrog_Utils::contains( $file_path, WP_PLUGIN_DIR . '/amp/' ) &&
     355                                    ! PageFrog_Utils::contains( $file_path, WP_PLUGIN_DIR . '/pagefrog/' ) &&
     356                                    ! PageFrog_Utils::contains( $file_path, WP_PLUGIN_DIR . '/pageforg-wp/' )
     357                                    ) {
     358                                    // this one should be removed, add it to the list
     359                                    $to_remove[] = array(
     360                                        'hook' => $hook,
     361                                        'callable' => $callable_group['function'],
     362                                        'priority' => $priority
     363                                    );
     364                                }
     365                            } else if (
     366                                PageFrog_Utils::ends_with( $file_path, 'functions.php' ) &&
     367                                PageFrog_Utils::contains( $file_path, 'themes' )
     368                            ) {
     369                                // this is probably good to remove too
     370                                $to_remove[] = array(
     371                                    'hook' => $hook,
     372                                    'callable' => $callable_group['function'],
     373                                    'priority' => $priority
     374                                );
     375                            }
     376                        } catch ( ReflectionException $e ) {
     377                            // it's a private function, must be wordpress core stuff. Keep this one.
     378                        }
     379                    }
     380                }
     381            }
     382
     383            foreach ( $to_remove as $remove ) {
     384                // remove the filter
     385                $success = remove_filter($remove['hook'], $remove['callable'], $remove['priority']);
     386            }
     387            return $to_remove;
     388        }
     389        return array();
    287390    }
    288391
     
    806909    public function amp_render_template( $post_id ) {
    807910        if ( wp_amp_plugin_is_installed() && wp_amp_plugin_is_active() ) {
    808             ///////////////////////////////////
    809             // TEMP AMP PLUGIN COMPATIBILITY //
    810             ///////////////////////////////////
    811             $fct = new ReflectionFunction( 'amp_render' );
    812             $is_v1 = $fct->getNumberOfRequiredParameters() == 0;
    813             if ( $is_v1 ) {
    814                 amp_render();
    815             } else {
    816                 amp_render( $post_id );
    817             }
    818             ///////////////////////////////////////
    819             // END TEMP AMP PLUGIN COMPATIBILITY //
    820             ///////////////////////////////////////
     911            amp_render( $post_id );
    821912            return;
    822913        } else if ( wp_amp_plugin_is_installed() ){
     
    829920    }
    830921
    831   ///////////////////////////////////
    832     // TEMP AMP PLUGIN COMPATIBILITY //
    833     ///////////////////////////////////
    834     public function render_v01_amp ( $post_id ) {
    835         if ( wp_amp_plugin_is_installed() && wp_amp_plugin_is_active() ) {
    836             $fct = new ReflectionFunction( 'amp_render' );
    837             $is_v1 = $fct->getNumberOfRequiredParameters() == 0;
    838             if ( ! $is_v1 ) {
    839                 $amp_post = new AMP_Post( $post_id );
    840                 include( dirname(__FILE__) . '/pagefrog-amp-template.php');
    841                 exit;
    842             }
    843         } else if ( wp_amp_plugin_is_installed() ){
    844             echo "<html><head></head><body style='background-color:white;'><h1>To generate AMP previews, you must activate the Wordpress AMP plugin. Click the button above to get started.</h1></body></html>";
    845             return;
    846         } else {
    847             echo "<html><head></head><body style='background-color:white;'><h1>To generate AMP previews, you must install the official Wordpress AMP plugin. Click the button above to get started.</h1></body></html>";
    848             return;
    849         }
    850     }
    851 
    852     public function add_to_v01_amp_head( $amp_post ) {
    853         $fct = new ReflectionFunction( 'amp_render' );
    854         $is_v1 = $fct->getNumberOfRequiredParameters() == 0;
    855         if ( ! $is_v1 ) {
    856             ?>
    857             <title><?php echo wp_get_document_title(); ?></title>
    858             <link rel="canonical" href="<?php echo esc_url( get_permalink() ); ?>" />
    859             <?php
    860             foreach ( $amp_post->get_scripts() as $element => $script ) : ?>
    861                 <script custom-element="<?php echo esc_attr( $element ); ?>" src="<?php echo esc_url( $script ); ?>" async></script>
    862             <?php endforeach; ?>
    863             <script src="https://cdn.ampproject.org/v0.js" async></script>
    864             <script type="application/ld+json"><?php echo json_encode( $amp_post->get_metadata() ); ?></script>
    865             <?php
    866         }
    867     }
    868 
    869     public function change_v01_amp_url( $url ) {
    870 
    871         $fct = new ReflectionFunction( 'amp_render' );
    872         $is_v1 = $fct->getNumberOfRequiredParameters() == 0;
    873         if ( ! $is_v1 ) {
    874             if ( PageFrog_Utils::ends_with( $url, '/amp/' ) ) {
    875                 $exploded = explode( '/', $url );
    876                 array_pop( $exploded );
    877                 array_pop( $exploded );
    878                 $url = implode( '/', $exploded );
    879             } else if ( PageFrog_Utils::ends_with( $url, '/amp' ) ) {
    880                 $exploded = explode( '/', $url );
    881                 array_pop( $exploded );
    882                 $url = implode( '/', $exploded );
    883             }
    884             $seperator = (parse_url( $url, PHP_URL_QUERY ) == NULL ) ? '?' : '&';
    885             $url .= $seperator . 'amp=1';
    886         }
    887         return $url;
    888     }
    889     ///////////////////////////////////////
    890     // END TEMP AMP PLUGIN COMPATIBILITY //
    891     ///////////////////////////////////////
    892 
    893922    public function amp_add_custom_post_support() {
    894923        if ( defined( 'AMP_QUERY_VAR' ) ) {
     
    910939        $pagefrog_metadata = new PageFrog_PostStatus( $post );
    911940        return ! $pagefrog_metadata->get_amp_status();
    912     }
    913 
    914     public function set_amp_template_file( $file ) {
    915         return dirname(__FILE__) . '/pagefrog-amp-template.php';
    916941    }
    917942
     
    11531178
    11541179    public function set_new_post_metadata( $post_id, $post, $update ) {
    1155         $new_post = new PageFrog_NewPostSettings_Storage();
    1156         $status = new PageFrog_PostStatus( $post_id );
    1157         $status->set_fbia_status( $new_post->get_fbia_enable_new_posts_bool_for( $post->post_type ) );
    1158         $status->set_amp_status( $new_post->get_amp_enable_new_posts_bool_for( $post->post_type ) && wp_amp_plugin_is_installed() && wp_amp_plugin_is_active() );
     1180        if ( ! $update ) {
     1181            $new_post = new PageFrog_NewPostSettings_Storage();
     1182            $status = new PageFrog_PostStatus( $post_id );
     1183            $status->set_fbia_status( $new_post->get_fbia_enable_new_posts_bool_for( $post->post_type ) );
     1184            $status->set_amp_status( $new_post->get_amp_enable_new_posts_bool_for( $post->post_type ) && wp_amp_plugin_is_installed() && wp_amp_plugin_is_active() );
     1185        }
    11591186    }
    11601187}
  • pagefrog/trunk/admin/class-pagefrog-new-post-settings-storage.php

    r1357722 r1361838  
    106106    }
    107107
     108    public function get_amp_disable_other_plugins_bool() {
     109        return $this->settings['amp_disable_other_plugins'] ? true : false;
     110    }
     111
     112    public function get_amp_disable_other_plugins_string() {
     113        return $this->get_amp_disable_other_plugins_bool() ? 'true' : 'false';
     114    }
     115
     116    public function get_fbia_disable_other_plugins_bool() {
     117        return $this->settings['fbia_disable_other_plugins'] ? true : false;
     118    }
     119
     120    public function get_fbia_disable_other_plugins_string() {
     121        return $this->get_fbia_disable_other_plugins_bool() ? 'true' : 'false';
     122    }
     123
     124    /** This function is for TESTING ONLY. Do not call it **/
     125    public function __set_amp_disable_other_plugins( $val ) {
     126        if ( $val === true ) {
     127            $this->settings['amp_disable_other_plugins'] = 1;
     128        } else {
     129            $this->settings['amp_disable_other_plugins'] = 0;
     130        }
     131    }
     132
     133    /** This function is for TESTING ONLY. Do not call it **/
     134    public function __get_settings() {
     135        return $this->settings;
     136    }
     137
    108138    /**
    109139     * A convenience method to generate reliable data from the user-inputted values and provide
     
    122152                    $clean_data[$key] = 0;
    123153                }
     154            }
     155        }
     156
     157        if ( isset( $data['amp_disable_other_plugins'] ) && PageFrog_Utils::string_isnt_empty( $data['amp_disable_other_plugins'] ) ) {
     158            if ( $data['amp_disable_other_plugins'] === 'true' || $data['amp_disable_other_plugins'] === true ) {
     159                $clean_data['amp_disable_other_plugins'] = 1;
     160            } else {
     161                $clean_data['amp_disable_other_plugins'] = 0;
     162            }
     163        }
     164
     165        if ( isset( $data['fbia_disable_other_plugins'] ) && PageFrog_Utils::string_isnt_empty( $data['fbia_disable_other_plugins'] ) ) {
     166            if ( $data['fbia_disable_other_plugins'] === 'true' || $data['fbia_disable_other_plugins'] === true ) {
     167                $clean_data['fbia_disable_other_plugins'] = 1;
     168            } else {
     169                $clean_data['fbia_disable_other_plugins'] = 0;
    124170            }
    125171        }
     
    148194    'amp_enable_new_post' => 1,
    149195    'fbia_enable_new_post' => 1,
     196    'amp_disable_other_plugins' => 0,
     197    'fbia_disable_other_plugins' => 0
    150198);
    151199?>
  • pagefrog/trunk/admin/pagefrog-settings.php

    r1359856 r1361838  
    2121        'render_new_post_main_description',
    2222        $GLOBALS['PAGEFROG_SETTINGS_PAGE_SLUG']
     23    );
     24
     25    add_settings_field(
     26        'amp_disable_other_plugins',
     27        '',
     28        'render_amp_disable_other_plugins',
     29        $GLOBALS['PAGEFROG_SETTINGS_PAGE_SLUG'],
     30        PageFrog_NewPostSettings_Storage::OPTIONS_KEY,
     31        array( 'new_post' => $new_post )
     32    );
     33
     34    add_settings_field(
     35        'fbia_disable_other_plugins',
     36        '',
     37        'render_fbia_disable_other_plugins',
     38        $GLOBALS['PAGEFROG_SETTINGS_PAGE_SLUG'],
     39        PageFrog_NewPostSettings_Storage::OPTIONS_KEY,
     40        array( 'new_post' => $new_post )
    2341    );
    2442
     
    5775    ?><input type="hidden" name="<?php echo PageFrog_NewPostSettings_Storage::OPTIONS_KEY; ?>[fbia_enable_new_<?php echo $args['label'] ?>]" value="<?php echo $args['new_post']->get_fbia_enable_new_posts_string_for( $args['label'] ); ?>"><?php
    5876}
    59 
     77function render_amp_disable_other_plugins( $args ) {
     78    ?><input type="hidden" name="<?php echo PageFrog_NewPostSettings_Storage::OPTIONS_KEY; ?>[amp_disable_other_plugins]" value="<?php echo $args['new_post']->get_amp_disable_other_plugins_string(); ?>"><?php
     79}
     80function render_fbia_disable_other_plugins( $args ) {
     81    ?><input type="hidden" name="<?php echo PageFrog_NewPostSettings_Storage::OPTIONS_KEY; ?>[fbia_disable_other_plugins]" value="<?php echo $args['new_post']->get_fbia_disable_other_plugins_string(); ?>"><?php
     82}
    6083
    6184
     
    271294                            </div>
    272295                            <div class="row">
     296                                <div class="col-sm-12 margin-bottom">
     297                                    <div class="row">
     298                                    <div class="col-sm-3">
     299                                        <p><strong>Other Settings</strong></p>
     300                                    </div>
     301                                    <div class="col-sm-9">
     302                                        <div class="row">
     303                                            <div class="col-sm-12">
     304                                                <div class="well">
     305                                                    <div class="row">
     306                                                        <div class="col-sm-12 margin-top-bottom">
     307                                                            <label for="amp-disable-other-plugins">
     308                                                                <input id="amp-disable-other-plugins" type="checkbox" class="sync-form" name="<?php echo PageFrog_NewPostSettings_Storage::OPTIONS_KEY; ?>[amp_disable_other_plugins]" <?php if ( $new_post->get_amp_disable_other_plugins_bool() ) echo 'checked="checked"'; ?>>&nbsp;Force AMP compliance by removing other plugins/functions from AMP pages.
     309                                                            </label>
     310                                                        </div>
     311                                                    </div>
     312                                                </div>
     313                                            </div>
     314                                        </div>
     315                                    </div>
     316                                    </div>
     317                                </div>
     318                            </div>
     319                            <div class="row">
    273320                                <div class="col-sm-12 margin-top-bottom" style="margin-top: 50px">
    274321                                    <input type="submit" class="button green pull-right submit-new-posts-form" value="Save All Settings">
  • pagefrog/trunk/includes/class-pagefrog.php

    r1359856 r1361838  
    7070
    7171        $this->plugin_name = 'pagefrog';
    72         $this->version = '1.0.7.1';
     72        $this->version = '1.0.7.2';
    7373
    7474        $this->load_dependencies();
     
    184184        // previews on the posts table
    185185        $this->loader->add_action( 'admin_init', $plugin_admin, 'add_post_listing_table_hooks' );
    186        
    187 
    188         ///////////////////////////////////
    189         // TEMP AMP PLUGIN COMPATIBILITY //
    190         ///////////////////////////////////
    191         $this->loader->add_action( 'pre_amp_render', $plugin_admin, 'render_v01_amp' );
    192         $this->loader->add_action( 'amp_head', $plugin_admin, 'add_to_v01_amp_head' );
    193         $this->loader->add_filter( 'amp_get_url', $plugin_admin, 'change_v01_amp_url' );
    194         ///////////////////////////////////////
    195         // END TEMP AMP PLUGIN COMPATIBILITY //
    196         ///////////////////////////////////////
    197186
    198187        // amp rendering
    199188        $this->loader->add_action( 'amp_init', $plugin_admin, 'amp_add_custom_post_support' );
    200189        $this->loader->add_action( 'wp', $plugin_admin, 'amp_add_custom_post_support' );
    201         $this->loader->add_filter( 'amp_template_file', $plugin_admin, 'set_amp_template_file', 10, 1 );
    202190        $this->loader->add_filter( 'amp_skip_post', $plugin_admin, 'should_amp_be_active_for_post', 10, 2 );
    203191        $this->loader->add_action( 'init', $plugin_admin, 'hook_up_previews' );
    204192        $this->loader->add_action( 'wp', $plugin_admin, 'maybe_handle_preview' );
     193        $this->loader->add_filter( 'wp', $plugin_admin, 'maybe_disable_plugins' );
    205194
    206195        // contact us form page
  • pagefrog/trunk/pagefrog.php

    r1359856 r1361838  
    1616 * Plugin URI:        http://pagefrog.com/
    1717 * Description:       The PageFrog plugin allows you to easily publish and manage your content directly from WordPress for Facebook Instant Articles (FBIA) and Google Accelerated Mobile Pages (AMP) with full support for ads and analytics.
    18  * Version:           1.0.7.1
     18 * Version:           1.0.7.2
    1919 * Author:            PageFrog Team
    2020 * Author URI:        http://pagefrog.com/
Note: See TracChangeset for help on using the changeset viewer.