Plugin Directory

Changeset 1387440


Ignore:
Timestamp:
04/05/2016 05:35:53 PM (10 years ago)
Author:
smartware.cc
Message:

Version 2.1 DEV-3

Location:
404page/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 404page/trunk/404page.js

    r1376500 r1387440  
    1010    window.location.href = jQuery( '#404page_test_link' ).text();
    1111  });
    12   jQuery( '#404page_admin_notice' ).click( function() {
     12  jQuery( '#404page_admin_notice .notice-dismiss' ).click( function() {
    1313    jQuery.ajax({
    1414      url: ajaxurl,
  • 404page/trunk/404page.php

    r1376500 r1387440  
    44Plugin URI: http://smartware.cc/free-wordpress-plugins/404page/
    55Description: Custom 404 the easy way! Set any page as custom 404 error page. No coding needed. Works with (almost) every Theme.
    6 Version: 2.1 DEV-2
     6Version: 2.1 DEV-3
    77Author: smartware.cc, Peter's Plugins
    88Author URI: http://smartware.cc
     
    2626    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2727*/
    28 
    29 
    30 /* As of Version 2.0 the 404page Plugin no longer uses the 404_template filter, because this does not work with WPML, bbPress and Customizr */
    31 /* The posts_results filter is the only solution that works for all of them */
    3228
    3329if ( ! defined( 'WPINC' ) ) {
     
    4642        $this->plugin_name = '404page';
    4743    $this->plugin_slug = '404page';
    48         $this->version = '2.1 DEV-2';
     44        $this->version = '2.1 DEV-3';
    4945    $this->get_settings();
    5046    $this->init();
     
    5955    $this->settings['404page_method'] = $this->get_404page_method();
    6056  }
    61  
     57 
     58  // do plugin init
    6259  private function init() {
    6360   
     
    6562   
    6663    if ( !is_admin() ) {
     64     
     65      add_action( 'init', array( $this, 'set_mode' ) );
     66     
     67    } else {
     68     
     69      add_action( 'admin_init', array( $this, 'admin_init' ) );
     70      add_action( 'admin_menu', array( $this, 'admin_menu' ) );
     71      add_action( 'admin_head', array( $this, 'admin_css' ) );
     72      add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_settings_link' ) );
     73     
     74      if ( $this->settings['404page_hide'] and $this->settings['404page_page_id'] > 0 ) {
     75        add_action( 'pre_get_posts' ,array ( $this, 'exclude_404page' ) );
     76      }
     77     
     78      if ( 'NOT_DISMISSED' == get_option( '404page_notice_dismissed', 'NOT_DISMISSED' ) )  {
     79        add_action( 'admin_notices', array( $this, 'admin_notice' ) );
     80        add_action( 'wp_ajax_nopriv_404page_dismiss_admin_notice', array( $this, 'dismiss_admin_notice' ) );
     81        add_action( 'wp_ajax_404page_dismiss_admin_notice', array( $this, 'dismiss_admin_notice' ) );
     82      }
     83    }
     84   
     85  }
     86 
     87  // init filters
     88  function set_mode() {
     89   
     90    if ( defined( 'CUSTOMIZR_VER' ) ) {
     91     
     92      // Customizr Compatibility Mode
     93     
     94      add_filter( 'tc_404_header_content', array( $this, 'show404title_customizr_mode' ), 999 );
     95      add_filter( 'tc_404_content', array( $this, 'show404_customizr_mode' ), 999 );
     96      add_filter( 'tc_404_selectors', array( $this, 'show404articleselectors_customizr_mode' ), 999 );
     97     
     98    } else {
     99     
    67100      if ( $this->settings['404page_method'] != 'STD' ) {
    68         add_filter( 'posts_results', array( $this, 'show404_compatiblity_mode' ), 999 );
     101       
     102        // Compatibility Mode
     103        add_filter( 'posts_results', array( $this, 'show404_compatiblity_mode' ), 999 );
     104       
    69105      } else {
     106       
     107        // Standard Mode
    70108        add_filter( '404_template', array( $this, 'show404_standard_mode' ), 999 );
    71109        if ( $this->settings['404page_fire_error'] ) {
    72110          add_action( 'template_redirect', array( $this, 'do_404_header_standard_mode' ) );
    73111        }
    74       }
    75     } else {
    76       add_action( 'admin_init', array( $this, 'admin_init' ) );
    77       add_action( 'admin_menu', array( $this, 'admin_menu' ) );
    78       add_action( 'admin_head', array( $this, 'admin_css' ) );
    79       add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_settings_link' ) );
    80       if ( $this->settings['404page_hide'] and $this->settings['404page_page_id'] > 0 ) {
    81         add_action( 'pre_get_posts' ,array ( $this, 'exclude_404page' ) );
    82       }
    83       if ( 'NOT_DISMISSED' == get_option( '404page_notice_dismissed', 'NOT_DISMISSED' ) )  {
    84         add_action( 'admin_notices', array( $this, 'admin_notice' ) );
    85         add_action( 'wp_ajax_nopriv_404page_dismiss_admin_notice', array( $this, 'dismiss_admin_notice' ) );
    86         add_action( 'wp_ajax_404page_dismiss_admin_notice', array( $this, 'dismiss_admin_notice' ) );
    87       }
    88     }
    89    
    90   }
    91  
    92   // redirect 404 page - standard mode
     112       
     113      }
     114    }
     115   
     116  }
     117 
     118  // show 404 page - Standard Mode
    93119  function show404_standard_mode( $template ) {
     120   
    94121    global $wp_query;
    95122    $pageid = $this->settings['404page_page_id'];
     
    104131    }
    105132    return $template;
    106   }
    107  
    108   // redirect 404 page - compatibility mode - introduced in version 2.0
    109   // as of v2.1 we do not alter the posts argument here because this does not work with SiteOrigin's Page Builder Plugin, template_include filter introduced
     133   
     134  }
     135 
     136  // show 404 page - Compatibility Mode
    110137  function show404_compatiblity_mode( $posts ) {
     138   
    111139    // remove the filter so we handle only the first query - no custom queries
    112     remove_filter( 'posts_results', array( $this, 'show404' ), 999 );
     140    remove_filter( 'posts_results', array( $this, 'show404_compatiblity_mode' ), 999 );
     141   
    113142    $pageid = $this->settings['404page_page_id'];
    114143    if ( 0 != $pageid ) {
     
    117146       
    118147        if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
     148         
    119149          // WPML is active
    120150          $pageid = apply_filters( 'wpml_object_id', $pageid, 'page', true );
     151         
     152        } elseif ( defined( 'POLYLANG_VERSION' ) ) {
     153         
     154          // Polylang is active
     155          $translatedpageid = pll_get_post( $pageid );
     156          if ( !empty( $translatedpageid ) && 'publish' == get_post_status( $translatedpageid ) ) {
     157            $pageid = $translatedpageid;
     158          }
    121159        }
     160       
     161        // as of v2.1 we do not alter the posts argument here because this does not work with SiteOrigin's Page Builder Plugin, template_include filter introduced
    122162        $this->postid = $pageid;
    123163        $this->template = get_page_template_slug( $pageid );
     
    135175        if ( $this->settings['404page_fire_error'] ) {
    136176          $curpageid = $posts[0]->ID;
     177         
    137178          if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
    138             // WPML is active - get the post ID of the default language
     179           
     180           // WPML is active - get the post ID of the default language
    139181            global $sitepress;
    140182            $curpageid = apply_filters( 'wpml_object_id', $curpageid, 'page', $sitepress->get_default_language() );
    141183            $pageid = apply_filters( 'wpml_object_id', $pageid, 'page', $sitepress->get_default_language() );
     184           
     185          } elseif ( defined( 'POLYLANG_VERSION' ) ) {
     186           
     187            // Polylang is active - get the post ID of the default language
     188            $curpageid = pll_get_post( $curpageid, pll_default_language() );
     189            $pageid = pll_get_post( $pageid, pll_default_language() );
     190         
    142191          }
     192         
    143193          if ( $pageid == $curpageid ) {
    144194            add_action( 'wp', array( $this, 'do_404_header' ) );
     
    152202  }
    153203 
    154   // send a 404 HTTP header - standard mode
     204  // send a 404 HTTP header - Standard Mode
    155205  function do_404_header_standard_mode() {
    156206    if ( is_page() && get_the_ID() == $this->settings['404page_page_id'] && !is_404() ) {
    157       // we do not have to take care about WPML because WPML only works in compatibility mode
    158207      status_header( 404 );
    159208      nocache_headers();
     
    161210  }
    162211 
    163   // send a 404 HTTP header - compatibility mode
     212  // send a 404 HTTP header - Compatibility Mode
    164213  function do_404_header() {
    165214    // remove the action so we handle only the first query - no custom queries
     
    175224  }
    176225 
    177   // here the real magic happens...
    178   function template_include_404( $template ) {
    179     // as of v2.1 we do not alter the posts in show404, because this does not work with SiteOrigin's Page Builder Plugin
    180     global $wp_query;
    181     $wp_query->posts = array();
    182     $wp_query->posts[] = get_post( $this->postid );
    183     $wp_query->queried_object_id = $this->postid;
    184     $wp_query->queried_object = $wp_query->posts[0];
    185     $wp_query->post_count = 1;
    186     $wp_query->found_posts = 1;
    187     $wp_query->current_post = -1;
    188     $wp_query->is_page = true;
    189     $wp_query->is_single = false;
    190     $wp_query->is_404 = false;
    191     if ( $this->template != '' ) {
    192       $template = $this->template;
    193     }
    194     return $template;
     226  // show title - Customizr Compatibility Mode
     227  function show404title_customizr_mode( $title ) {
     228    return '<h1 class="entry-title">' . get_the_title( $this->settings['404page_page_id'] ) . '</h1>';
     229  }
     230 
     231  // show content - Customizr Compatibility Mode
     232  function show404_customizr_mode( $content ) {
     233    return '<div class="entry-content">' . apply_filters( 'the_content', get_post_field( 'post_content', $this->settings['404page_page_id'] ) ) . '</div>';
     234  }
     235 
     236  // change article selectors - Customizr Compatibility Mode
     237  function show404articleselectors_customizr_mode( $selectors ) {
     238    return 'id="post-' . $this->settings['404page_page_id'] . '" ' . 'class="' . join( ' ', get_post_class( 'row-fluid', $this->settings['404page_page_id'] ) ) . '"';
    195239  }
    196240 
     
    211255  // add css
    212256  function admin_css() {
    213     echo '<style type="text/css">#select404page" {width: 100%}</style>';
     257    echo '<style type="text/css">#select404page {width: 100%; }';
     258    if ( $this->settings['404page_page_id'] > 0 ) {
     259      echo ' #the-list #post-' . $this->settings['404page_page_id'] . ' .column-title {min-height: 32px; background-position: left top; background-repeat: no-repeat; background-image: url(' . plugins_url( 'pluginicon.png', __FILE__ ) . '); padding-left: 40px;}';
     260    }
     261    echo '</style>';
    214262  }
    215263 
     
    242290  // handle the settings field method
    243291  function admin_method() {
    244     echo '<p><input type="radio" id="404page_settings_method_standard" name="404page_method" value="STD"' . checked( 'STD', $this->settings['404page_method'], false ) . '/>';
     292    if ( defined( 'CUSTOMIZR_VER' ) || defined( 'ICL_SITEPRESS_VERSION' ) || defined( 'POLYLANG_VERSION' ) || defined( 'SITEORIGIN_PANELS_VERSION' ) || class_exists( 'bbPress' ) ) {
     293      $dis = ' disabled="disabled"';
     294    } else {
     295      $dis = '';
     296    }
     297    echo '<p><input type="radio" id="404page_settings_method_standard" name="404page_method" value="STD"' . checked( 'STD', $this->settings['404page_method'], false ) . $dis . ' />';
    245298    echo '<label for="404page_settings_method_standard">' . __( 'Standard Mode', '404page' ) . '</label></p>';
    246299     
    247     echo '<p><input type="radio" id="404page_settings_method_compatibility" name="404page_method" value="CMP"' . checked( 'CMP', $this->settings['404page_method'], false ) . '/>';
     300    echo '<p><input type="radio" id="404page_settings_method_compatibility" name="404page_method" value="CMP"' . checked( 'CMP', $this->settings['404page_method'], false ) . $dis . '/>';
    248301    echo '<label for="404page_settings_method_compatibility">' . __( 'Compatibility Mode', '404page' ) . '</label></p>';
    249302   
    250     echo '<p><span class="dashicons dashicons-info"></span>&nbsp;' . __( 'Standard Mode uses the WordPress Template System and should work in most cases. If the 404page plugin does not work properly, probably you are using a theme or plugin that modifies the WordPress Template System. In this case the Compatibility Mode maybe can fix the problem, although it cannot be guaranteed that every possible configuration can be handled by Compatibility Mode. Standard Mode is the recommended method, only switch to Compatibility Mode if you have any problems.', '404page' ) . '</p>';
     303    if ( defined( 'CUSTOMIZR_VER' ) ) {
     304      echo '<p><span class="dashicons dashicons-warning"></span>&nbsp;' . __( 'Customizr Theme detected. The 404page Plugin works in Customizr Compatibility Mode.', '404page' ) . ' (<a href="#">' . __( 'Read more', '404page' ) . '</a>)</p>';
     305    } elseif ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
     306      echo '<p><span class="dashicons dashicons-warning"></span>&nbsp;' . __( 'WPML Plugin detected. Operating Method set to Compatibility Mode automatically.', '404page' ) . ' (<a href="#">' . __( 'Read more', '404page' ) . '</a>)</p>';
     307    } elseif ( defined( 'POLYLANG_VERSION' ) ) {
     308      echo '<p><span class="dashicons dashicons-warning"></span>&nbsp;' . __( 'Polylang Plugin detected. Operating Method set to Compatibility Mode automatically', '404page' ) . ' (<a href="#">' . __( 'Read more', '404page' ) . '</a>)</p>';
     309    } elseif ( defined( 'SITEORIGIN_PANELS_VERSION' ) ) {
     310      echo '<p><span class="dashicons dashicons-warning"></span>&nbsp;' . __( 'Page Builder by SiteOrigin Plugin detected. Operating Method set to Compatibility Mode automatically', '404page' ) . ' (<a href="#">' . __( 'Read more', '404page' ) . '</a>)</p>';
     311    } elseif ( class_exists( 'bbPress' ) ) {
     312      echo '<p><span class="dashicons dashicons-warning"></span>&nbsp;' . __( 'bbPress Plugin detected. Operating Method set to Compatibility Mode automatically', '404page' ) . ' (<a href="#">' . __( 'Read more', '404page' ) . '</a>)</p>';
     313    } else {
     314      echo '<p><span class="dashicons dashicons-info"></span>&nbsp;' . __( 'Standard Mode uses the WordPress Template System and should work in most cases. If the 404page plugin does not work properly, probably you are using a theme or plugin that modifies the WordPress Template System. In this case the Compatibility Mode maybe can fix the problem, although it cannot be guaranteed that every possible configuration can be handled by Compatibility Mode. Standard Mode is the recommended method, only switch to Compatibility Mode if you have any problems.', '404page' ) . '</p>';
     315    }
    251316  }
    252317 
     
    312377    if ( current_user_can( 'manage_options' ) ) {
    313378      echo '<div class="notice notice-info is-dismissible" id="404page_admin_notice"><p><strong>404page Plugin:</strong> ';
    314       _e( 'Please check Operating Method in <a href="' . admin_url( 'themes.php?page=404pagesettings' ) . '">' . __( 'Settings', '404page' ) . '</a>', '404page' );
     379      if ( defined( 'CUSTOMIZR_VER' ) ) {
     380        // Customizr Theme
     381        _e( 'Customizr Theme detected. The 404page Plugin works in Customizr Compatibility Mode.', '404page' );
     382      } elseif ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
     383        // WPML
     384        _e( 'WPML Plugin detected. Operating Method is set to Compatibility Mode automatically to make the 404page Plugin work with WPML.', '404page' );
     385      } elseif ( defined( 'POLYLANG_VERSION' ) ) {
     386        // Polylang
     387        _e( 'Polylang Plugin detected. Operating Method is set to Compatibility Mode automatically to make the 404page Plugin work with Polylang.', '404page' );
     388      } elseif ( defined( 'SITEORIGIN_PANELS_VERSION' ) ) {
     389        // Page Builder by SiteOrigin
     390        _e( 'Page Builder by SiteOrigin Plugin detected. Operating Method is set to Compatibility Mode automatically to make the 404page Plugin work with Page Builder by SiteOrigin.', '404page' );
     391      } elseif ( class_exists( 'bbPress' ) ) {
     392        // bbPress
     393        _e( 'bbPress Plugin detected. Operating Method is set to Compatibility Mode automatically to make the 404page Plugin work with bbPress.', '404page' );
     394      } else {
     395        _e( 'Please check Operating Method.', '404page' );
     396      }
     397      echo '<br /><a href="' . admin_url( 'themes.php?page=404pagesettings' ) . '">' . __( 'Settings', '404page' ) . '</a>';
    315398      echo '</p></div>';
    316399    }
     
    352435  // returns the selected method
    353436  private function get_404page_method() {
    354     return get_option( '404page_method', 'STD' );
     437    if ( defined( 'ICL_SITEPRESS_VERSION' ) || defined( 'POLYLANG_VERSION' ) || defined( 'SITEORIGIN_PANELS_VERSION' ) || class_exists( 'bbPress' ) ) {
     438      // WPML or bbPress is active
     439      return 'CMP';
     440    } else {
     441      return get_option( '404page_method', 'STD' );
     442    }
    355443  }
    356444 
  • 404page/trunk/readme.txt

    r1366885 r1387440  
    1717**See also [Plugin Homepage](http://smartware.cc/free-wordpress-plugins/404page/) and [Plugin Doc](http://smartware.cc/docs/404page/)**
    1818
    19 = Version 2.0 Update Notice =
    20 * The settings page was moved from 'Settings' to 'Appearance' menu.
    21 * Version 2.0 is more or less a completely new development. This was necessary to solve several compatibility issues. 404page now works with the [WPML WordPress Multilingual Plugin](https://wpml.org/), the [bbPress Forum Plugin](https://wordpress.org/plugins/bbpress/) and the [Customizr Theme](https://wordpress.org/themes/customizr/). [Read more](http://smartware.cc/blog/2016/02/23/the-404page-plugin-now-works-with-wpml-and-other-enhancements/).
     19= Version 2.1 Update Notice =
     20Please take a look at the [release notes](LINK).
    2221
    2322https://www.youtube.com/watch?v=VTL07Lf0IsY
     
    8079== Changelog ==
    8180
     81= 2.1 (2016-04-XX) =
     82* introduction of selectable Operating Methods
     83* several changes to Compatibility Mode for improved WPML and bbPress compatibility plus compatibility with Page Builder by SiteOrigin
     84* Polylang compatibility
     85* automatic switch to Compatibility Mode if WPML, bbPress, Polylang or Page Builder by SiteOrigin is detected
     86* completely new Customizr (automatically enabled if Customizr is detected)
     87* firing an 404 error in case of directly accessing the 404 error page can now be deactivated
     88* option to hide the 404 error page from the Pages list
     89* 404 error test
     90
    8291= 2.0 (2016-03-08) =
    8392* WPML compatibility
Note: See TracChangeset for help on using the changeset viewer.