Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Append extensions on Pages
- Plugin URI: http://www.skmukhiya.com.np
- Description: Appends different types of extensions like .html, .php, .asp, .jsp, .asp, .aspx on the wordpress pages when used with permalink
- Version: 1.1.1
- Author: dr.code.skm
- Author URI: https://www.odesk.com/users/~0182e0779315e50896
- Tags: append .html on pages, .html on permalink, add .html on pages, add .php on pages, add .aspx on pages, add .cfm on page, add .jsp on pages
- */
- // initiating hooks and plugins
- register_activation_hook(__FILE__, 'aeop_active');
- //initiating plugin deactivation hooks
- register_deactivation_hook(__FILE__, 'aeop_deactive');
- //Adding settings link
- function aeop_settings_link( $links ) {
- $links[] = '<a href="'.admin_url( 'admin.php?page=aeop_settings' ).'">Settings</a>';
- return $links;
- }
- add_filter( "plugin_action_links_".plugin_basename( __FILE__ ), 'aeop_settings_link' );
- add_action('admin_menu', 'aeop_settings_menu');
- //adding a dummy page
- function aeop_settings_menu() {
- add_submenu_page(
- 'options-general.php'
- , 'Append Extension settings'
- , 'Append Extension settings'
- , 'manage_options'
- , 'aeop_settings'
- , 'aeop_display_settings'
- );
- register_setting( 'aeop_settings_group', 'aeop_fburl' );
- register_setting( 'aeop_settings_group', 'aeop_allow_directly' );
- }
- function aeop_display_settings() {
- ?>
- <div class="clear"></div>
- <div id="welcome-panel" class="welcome-panel">
- <div class="welcome-panel-content">
- <h3>Appending Extension Settings Page!</h3>
- <p class="about-description">Add suitable Extensions to your WordPress page</p>
- <div class="welcome-panel-column-container">
- <div class="welcome-panel-column" style="width:50%;">
- <h4>Get Started</h4>
- <form method="post" action="options.php">
- <?php settings_fields( 'aeop_settings_group' ); ?>
- <?php do_settings_sections( 'aeop_settings_group' ); ?>
- <table class="form-table">
- <tr valign="top">
- <th scope="row">Enter the extension you want to append?</th>
- <td><input type="text" name="aeop_fburl" value="<?php echo get_option('aeop_fburl'); ?>" /></td>
- </tr>
- <tr><i>You can enter valid extensions such as .html, .htm, .jsp, .php, .asp, .cfm and .aspx only</i></tr>
- <tr valign="top">
- <th scope="row">Still allow people to access urls without extension?</th>
- <td> No: <input type="radio" name="aeop_allow_directly" value="0" <?php checked(get_option('aeop_allow_directly'),0);?> /> Yes <input type="radio" name="aeop_allow_directly" value="1" <?php checked(get_option('aeop_allow_directly'),1);?> /></td>
- </tr>
- <tr><i>you can allow or forbid</i></tr>
- </table>
- <?php
- $other_attributes = array( 'id' => 'aeop-submit-button' );
- submit_button( 'Save Settings', 'primary', 'wpdocs-save-settings', true, $other_attributes );
- ?>
- <p>Save your permalink setting everytime you update extension.</p>
- </form>
- </div>
- <div class="welcome-panel-column welcome-panel-last">
- <h4>More Actions</h4>
- <ul>
- <li><div class="welcome-icon welcome-widgets-menus">Found this plugin Useful <a href="http://www.skmukhiya.com.np/donation-page/">Buy me a beer</a></div></li>
- <li><a href="mailto:[email protected]" class="welcome-icon welcome-comments">Contact Author For more support</a></li>
- <li><a href="http://www.skmukhiya.com.np/append-extensions-to-pages/" class="welcome-icon welcome-learn-more">Learn more about getting started</a></li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <?php }
- function validateExtension($extension){
- $extension = get_option('aeop_fburl');
- return ( in_array( $extension, array('.cfm','.html','.htm','.asp','.aspx','.jsp','.php')) ? $extension : "");
- }
- /**
- * aeop function to initiate the global settings permalink initiations
- * @param null
- * @return string
- **/
- function aeop_html_page_permalink($flush=false) {
- if (is_admin()) return;
- global $wp_rewrite;
- $ext=validateExtension(get_option('aeop_fburl')) ;
- //check, if people are allowed to enter some pages without the ending:
- $allowed_without_extension= get_option('aeop_allow_directly');
- if(stripos($_SERVER['REQUEST_URI'], $ext)=== false && $allowed_without_extension) {
- //do nothing, because they are allowed to view what they want
- }
- elseif ( !strpos($wp_rewrite->get_page_permastruct(),$ext )){
- $wp_rewrite->page_structure .= $ext;
- }
- if($flush) { $wp_rewrite->flush_rules(); }
- }
- add_action('init', 'aeop_html_page_permalink', -1);
- /**
- * aeop function to check page slash
- * @param string, string
- * @return string
- **/
- function aeop_no_page_slash($string, $type){
- global $wp_rewrite;
- if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){
- return untrailingslashit($string);
- }else{
- return $string;
- }
- }
- add_filter('user_trailingslashit', 'aeop_no_page_slash',66,2);
- /**
- * aeop function to activate the plugin
- * @param null
- * @return void
- **/
- function aeop_active() {
- add_option('aeop_fburl', '.html');
- add_option('aeop_allow_directly', 1);
- aeop_html_page_permalink(true);
- }
- /**
- * aeop function to deactivate the plugin
- * @param null
- * @return void
- **/
- function aeop_deactive() {
- global $wp_rewrite;
- $wp_rewrite->page_structure = str_replace(validateExtension(get_option('aeop_fburl')),"",$wp_rewrite->page_structure);
- $wp_rewrite->flush_rules();
- }
- ?>
Add Comment
Please, Sign In to add comment