Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.24 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Plugin Maker
  4. Plugin URI: http://www.cesarserna.com/wordpress-plugins/plugin-maker/
  5. Description: Creates a blank plugin template to activate and edit online. Plugins-->Plugin Maker
  6. Version: 1.0
  7. Author: Cesar Serna
  8. Author URI: http://www.cesarserna.com
  9. */
  10.  
  11. //------------------------------------------------------
  12. //Some basic security with nonce
  13. //------------------------------------------------------
  14. if (!function_exists('wp_nonce_field'))
  15. {
  16.     function pluginmaker_nonce_field($action = -1)
  17.     {
  18.         return;
  19.     }
  20.     $pluginmaker_nonce = -1;
  21. }
  22. else
  23. {
  24.     function pluginmaker_nonce_field($action = -1)
  25.     {
  26.         wp_nonce_field($action);
  27.     }
  28.     $pluginmaker_nonce = 'pluginmaker-nonce-key';
  29. }
  30.  
  31. //------------------------------------------------------
  32. //Next we assign a random key to this plugin to act
  33. //as an extra signature to help avoid security issues
  34. //------------------------------------------------------
  35. $pluginmaker_key = get_option('pluginmaker_key');
  36.  
  37. if ($pluginmaker_key == '')
  38. {
  39.     $pluginmaker_key = add_option('pluginmaker_key', rand(0, 9999));
  40. }
  41.  
  42. //------------------------------------------------------
  43. //Admin Interface
  44. //------------------------------------------------------
  45. function pm_adminpage()
  46. {
  47. global $pluginmaker_nonce, $pluginmaker_key;
  48.  
  49. if ($_POST['action'] == 'createnewplugin')
  50. {
  51.  
  52.     if (function_exists('current_user_can') && current_user_can('edit_plugins') && $_POST['pluginmaker_key'] == $pluginmaker_key)
  53.     {
  54.         //check_admin_referer('$pluginmaker_nonce', $pluginmaker_nonce);
  55.  
  56.         $plugin_file_name = $_POST['plugin_file_name'];
  57.         $plugin_name = $_POST['plugin_name'];
  58.         $plugin_uri = $_POST['plugin_uri'];
  59.         $plugin_description = $_POST['plugin_description'];
  60.         $plugin_version = $_POST['plugin_version'];
  61.         $plugin_author = $_POST['plugin_author'];
  62.         $plugin_author_uri = $_POST['plugin_author_uri'];
  63.            
  64.         $fileContents = "<?php
  65. /*
  66. Plugin Name: $plugin_name
  67. Plugin URI: $plugin_uri
  68. Description: $plugin_description
  69. Version: $plugin_version
  70. Author: $plugin_author
  71. Author URI: $plugin_author_uri
  72. */
  73. ?>";
  74.  
  75.  
  76.         $ourFileName = "../wp-content/plugins/" . $plugin_file_name;
  77.         if (!file_exists($ourFileName))
  78.         {
  79.             if (!strstr($ourFileName, '.php'))
  80.             {
  81.                 $pm_msg = "<p>Your file name needs to have the php extension.</p>";
  82.             }
  83.             else
  84.             {
  85.                 $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
  86.                 fwrite($ourFileHandle, $fileContents);
  87.                 fclose($ourFileHandle);
  88.                 $pm_msg = "<p>Start editing your new plugin <a href='/wp-admin/plugin-editor.php?file=$plugin_file_name'>$plugin_file_name</a>.</p>";
  89.             }
  90.         }
  91.         else
  92.         {
  93.             $pm_msg = "<p>A file exists with the file name you have chosen. Plugin not created.</p>";
  94.         }
  95.     }
  96.     else
  97.     {
  98.         wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
  99.     }
  100. }
  101. ?>
  102. <div class="wrap">
  103.   <h2>
  104.     <?php _e('Plugin Maker') ?>
  105.   </h2>
  106.   <?php
  107.     if ($pm_msg != '')
  108.     {
  109.         echo $pm_msg;
  110.     }
  111.   ?>
  112.   <form method="post">
  113.     <table>
  114.       <tr>
  115.         <td>Plugin File Name:</td>
  116.         <td>
  117.           <input type="text" name="plugin_file_name" value=""/>
  118.         </td>
  119.         <td>Example: myplugin.php</td>
  120.       </tr>
  121.       <tr>
  122.         <td>Plugin Name:</td>
  123.         <td>
  124.           <input type="text" name="plugin_name" value=""/>
  125.         </td>
  126.         <td>Example: My Plugin</td>
  127.       </tr>
  128.       <tr>
  129.         <td>Plugin URI:</td>
  130.         <td>
  131.           <input type="text" name="plugin_uri" value=""/>
  132.         </td>
  133.         <td>Example: http:/www.mysite.com/myplugin/</td>
  134.       </tr>
  135.       <tr>
  136.         <td>Description:</td>
  137.         <td>
  138.           <input type="text" name="plugin_description" value=""/>
  139.         </td>
  140.         <td>Example: My plugin does X Y and Z!</td>
  141.       </tr>
  142.       <tr>
  143.         <td>Version:</td>
  144.         <td>
  145.           <input type="text" name="plugin_version" value=""/>
  146.         </td>
  147.         <td>Example: 1.0 beta</td>
  148.       </tr>
  149.       <tr>
  150.         <td>Plugin Author:</td>
  151.         <td>
  152.           <input type="text" name="plugin_author" value=""/>
  153.         </td>
  154.         <td>Example: Joe Smith</td>
  155.       </tr>
  156.       <tr>
  157.         <td>Plugin Author URI:</td>
  158.         <td>
  159.           <input type="text" name="plugin_author_uri" value=""/>
  160.         </td>
  161.         <td>Example: http://www.mysite.com</td>
  162.       </tr>
  163.     </table>
  164.     <?php pluginmaker_nonce_field('$pluginmaker_nonce', $pluginmaker_nonce); ?>
  165.     <input type="hidden" name="pluginmaker_key" value="<?php echo $pluginmaker_key ?>" />
  166.     <input type="hidden" name="action" value="createnewplugin" />
  167.     <input type="submit"/>
  168.   </form>
  169. </div>
  170. <?php
  171. }
  172.  
  173. //------------------------------------------------------
  174. //Add To Admin Navigation
  175. //------------------------------------------------------
  176. function pm_setup_menu()
  177. {
  178.     add_submenu_page('plugins.php', 'Plugin Maker', 'Plugin Maker', 10, 'plugin-maker', 'pm_adminpage');
  179. }
  180. add_action('admin_menu', 'pm_setup_menu');
  181.  
  182. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement