Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Plugin Maker
- Plugin URI: http://www.cesarserna.com/wordpress-plugins/plugin-maker/
- Description: Creates a blank plugin template to activate and edit online. Plugins-->Plugin Maker
- Version: 1.0
- Author: Cesar Serna
- Author URI: http://www.cesarserna.com
- */
- //------------------------------------------------------
- //Some basic security with nonce
- //------------------------------------------------------
- if (!function_exists('wp_nonce_field'))
- {
- function pluginmaker_nonce_field($action = -1)
- {
- return;
- }
- $pluginmaker_nonce = -1;
- }
- else
- {
- function pluginmaker_nonce_field($action = -1)
- {
- wp_nonce_field($action);
- }
- $pluginmaker_nonce = 'pluginmaker-nonce-key';
- }
- //------------------------------------------------------
- //Next we assign a random key to this plugin to act
- //as an extra signature to help avoid security issues
- //------------------------------------------------------
- $pluginmaker_key = get_option('pluginmaker_key');
- if ($pluginmaker_key == '')
- {
- $pluginmaker_key = add_option('pluginmaker_key', rand(0, 9999));
- }
- //------------------------------------------------------
- //Admin Interface
- //------------------------------------------------------
- function pm_adminpage()
- {
- global $pluginmaker_nonce, $pluginmaker_key;
- if ($_POST['action'] == 'createnewplugin')
- {
- if (function_exists('current_user_can') && current_user_can('edit_plugins') && $_POST['pluginmaker_key'] == $pluginmaker_key)
- {
- //check_admin_referer('$pluginmaker_nonce', $pluginmaker_nonce);
- $plugin_file_name = $_POST['plugin_file_name'];
- $plugin_name = $_POST['plugin_name'];
- $plugin_uri = $_POST['plugin_uri'];
- $plugin_description = $_POST['plugin_description'];
- $plugin_version = $_POST['plugin_version'];
- $plugin_author = $_POST['plugin_author'];
- $plugin_author_uri = $_POST['plugin_author_uri'];
- $fileContents = "<?php
- /*
- Plugin Name: $plugin_name
- Plugin URI: $plugin_uri
- Description: $plugin_description
- Version: $plugin_version
- Author: $plugin_author
- Author URI: $plugin_author_uri
- */
- ?>";
- $ourFileName = "../wp-content/plugins/" . $plugin_file_name;
- if (!file_exists($ourFileName))
- {
- if (!strstr($ourFileName, '.php'))
- {
- $pm_msg = "<p>Your file name needs to have the php extension.</p>";
- }
- else
- {
- $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
- fwrite($ourFileHandle, $fileContents);
- fclose($ourFileHandle);
- $pm_msg = "<p>Start editing your new plugin <a href='/wp-admin/plugin-editor.php?file=$plugin_file_name'>$plugin_file_name</a>.</p>";
- }
- }
- else
- {
- $pm_msg = "<p>A file exists with the file name you have chosen. Plugin not created.</p>";
- }
- }
- else
- {
- wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
- }
- }
- ?>
- <div class="wrap">
- <h2>
- <?php _e('Plugin Maker') ?>
- </h2>
- <?php
- if ($pm_msg != '')
- {
- echo $pm_msg;
- }
- ?>
- <form method="post">
- <table>
- <tr>
- <td>Plugin File Name:</td>
- <td>
- <input type="text" name="plugin_file_name" value=""/>
- </td>
- <td>Example: myplugin.php</td>
- </tr>
- <tr>
- <td>Plugin Name:</td>
- <td>
- <input type="text" name="plugin_name" value=""/>
- </td>
- <td>Example: My Plugin</td>
- </tr>
- <tr>
- <td>Plugin URI:</td>
- <td>
- <input type="text" name="plugin_uri" value=""/>
- </td>
- <td>Example: http:/www.mysite.com/myplugin/</td>
- </tr>
- <tr>
- <td>Description:</td>
- <td>
- <input type="text" name="plugin_description" value=""/>
- </td>
- <td>Example: My plugin does X Y and Z!</td>
- </tr>
- <tr>
- <td>Version:</td>
- <td>
- <input type="text" name="plugin_version" value=""/>
- </td>
- <td>Example: 1.0 beta</td>
- </tr>
- <tr>
- <td>Plugin Author:</td>
- <td>
- <input type="text" name="plugin_author" value=""/>
- </td>
- <td>Example: Joe Smith</td>
- </tr>
- <tr>
- <td>Plugin Author URI:</td>
- <td>
- <input type="text" name="plugin_author_uri" value=""/>
- </td>
- <td>Example: http://www.mysite.com</td>
- </tr>
- </table>
- <?php pluginmaker_nonce_field('$pluginmaker_nonce', $pluginmaker_nonce); ?>
- <input type="hidden" name="pluginmaker_key" value="<?php echo $pluginmaker_key ?>" />
- <input type="hidden" name="action" value="createnewplugin" />
- <input type="submit"/>
- </form>
- </div>
- <?php
- }
- //------------------------------------------------------
- //Add To Admin Navigation
- //------------------------------------------------------
- function pm_setup_menu()
- {
- add_submenu_page('plugins.php', 'Plugin Maker', 'Plugin Maker', 10, 'plugin-maker', 'pm_adminpage');
- }
- add_action('admin_menu', 'pm_setup_menu');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement