retesere20

Untitled

Feb 19th, 2017
39
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Plugin Name: Append extensions on Pages
  4. Plugin URI: http://www.skmukhiya.com.np
  5. Description: Appends different types of extensions like .html, .php, .asp, .jsp, .asp, .aspx on the wordpress pages when used with permalink
  6. Version: 1.1.1
  7. Author: dr.code.skm
  8. Author URI: https://www.odesk.com/users/~0182e0779315e50896
  9. 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
  10. */
  11.  
  12.  
  13.  
  14. // initiating hooks and plugins
  15. register_activation_hook(__FILE__, 'aeop_active');
  16.  
  17. //initiating plugin deactivation hooks
  18. register_deactivation_hook(__FILE__, 'aeop_deactive');
  19.  
  20.  
  21. //Adding settings link
  22. function aeop_settings_link( $links ) {
  23. $links[] = '<a href="'.admin_url( 'admin.php?page=aeop_settings' ).'">Settings</a>';
  24. return $links;
  25. }
  26. add_filter( "plugin_action_links_".plugin_basename( __FILE__ ), 'aeop_settings_link' );
  27.  
  28.  
  29. add_action('admin_menu', 'aeop_settings_menu');
  30. //adding a dummy page
  31. function aeop_settings_menu() {
  32. add_submenu_page(
  33. 'options-general.php'
  34. , 'Append Extension settings'
  35. , 'Append Extension settings'
  36. , 'manage_options'
  37. , 'aeop_settings'
  38. , 'aeop_display_settings'
  39. );
  40. register_setting( 'aeop_settings_group', 'aeop_fburl' );
  41. register_setting( 'aeop_settings_group', 'aeop_allow_directly' );
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
  48. function aeop_display_settings() {
  49. ?>
  50. <div class="clear"></div>
  51. <div id="welcome-panel" class="welcome-panel">
  52. <div class="welcome-panel-content">
  53. <h3>Appending Extension Settings Page!</h3>
  54. <p class="about-description">Add suitable Extensions to your WordPress page</p>
  55. <div class="welcome-panel-column-container">
  56. <div class="welcome-panel-column" style="width:50%;">
  57. <h4>Get Started</h4>
  58. <form method="post" action="options.php">
  59. <?php settings_fields( 'aeop_settings_group' ); ?>
  60. <?php do_settings_sections( 'aeop_settings_group' ); ?>
  61. <table class="form-table">
  62. <tr valign="top">
  63. <th scope="row">Enter the extension you want to append?</th>
  64. <td><input type="text" name="aeop_fburl" value="<?php echo get_option('aeop_fburl'); ?>" /></td>
  65. </tr>
  66. <tr><i>You can enter valid extensions such as .html, .htm, .jsp, .php, .asp, .cfm and .aspx only</i></tr>
  67. <tr valign="top">
  68. <th scope="row">Still allow people to access urls without extension?</th>
  69. <td> No: <input type="radio" name="aeop_allow_directly" value="0" <?php checked(get_option('aeop_allow_directly'),0);?> /> &nbsp; Yes <input type="radio" name="aeop_allow_directly" value="1" <?php checked(get_option('aeop_allow_directly'),1);?> /></td>
  70. </tr>
  71. <tr><i>you can allow or forbid</i></tr>
  72. </table>
  73.  
  74. <?php
  75. $other_attributes = array( 'id' => 'aeop-submit-button' );
  76. submit_button( 'Save Settings', 'primary', 'wpdocs-save-settings', true, $other_attributes );
  77. ?>
  78. <p>Save your permalink setting everytime you update extension.</p>
  79. </form>
  80. </div>
  81.  
  82. <div class="welcome-panel-column welcome-panel-last">
  83. <h4>More Actions</h4>
  84. <ul>
  85. <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>
  86. <li><a href="mailto:itsmeskm99@gmail.com" class="welcome-icon welcome-comments">Contact Author For more support</a></li>
  87. <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>
  88. </ul>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. <?php }
  94.  
  95.  
  96.  
  97.  
  98. function validateExtension($extension){
  99. $extension = get_option('aeop_fburl');
  100. return ( in_array( $extension, array('.cfm','.html','.htm','.asp','.aspx','.jsp','.php')) ? $extension : "");
  101. }
  102.  
  103.  
  104.  
  105. /**
  106. * aeop function to initiate the global settings permalink initiations
  107. * @param null
  108. * @return string
  109. **/
  110. function aeop_html_page_permalink($flush=false) {
  111. if (is_admin()) return;
  112.  
  113. global $wp_rewrite;
  114. $ext=validateExtension(get_option('aeop_fburl')) ;
  115.  
  116. //check, if people are allowed to enter some pages without the ending:
  117. $allowed_without_extension= get_option('aeop_allow_directly');
  118. if(stripos($_SERVER['REQUEST_URI'], $ext)=== false && $allowed_without_extension) {
  119. //do nothing, because they are allowed to view what they want
  120. }
  121. elseif ( !strpos($wp_rewrite->get_page_permastruct(),$ext )){
  122. $wp_rewrite->page_structure .= $ext;
  123. }
  124. if($flush) { $wp_rewrite->flush_rules(); }
  125. }
  126. add_action('init', 'aeop_html_page_permalink', -1);
  127.  
  128.  
  129. /**
  130. * aeop function to check page slash
  131. * @param string, string
  132. * @return string
  133. **/
  134. function aeop_no_page_slash($string, $type){
  135. global $wp_rewrite;
  136. if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){
  137. return untrailingslashit($string);
  138. }else{
  139. return $string;
  140. }
  141. }
  142.  
  143. add_filter('user_trailingslashit', 'aeop_no_page_slash',66,2);
  144.  
  145.  
  146.  
  147. /**
  148. * aeop function to activate the plugin
  149. * @param null
  150. * @return void
  151. **/
  152. function aeop_active() {
  153. add_option('aeop_fburl', '.html');
  154. add_option('aeop_allow_directly', 1);
  155. aeop_html_page_permalink(true);
  156. }
  157.  
  158. /**
  159. * aeop function to deactivate the plugin
  160. * @param null
  161. * @return void
  162. **/
  163. function aeop_deactive() {
  164. global $wp_rewrite;
  165. $wp_rewrite->page_structure = str_replace(validateExtension(get_option('aeop_fburl')),"",$wp_rewrite->page_structure);
  166. $wp_rewrite->flush_rules();
  167. }
  168. ?>
RAW Paste Data