DEV Community

Cover image for 💢 How do you make your own WordPress Plugin ? in 2024
MrWhite
MrWhite

Posted on

💢 How do you make your own WordPress Plugin ? in 2024

💥💥 Let's spoil you a little 💥

💢 How do you make your own WordPress Plugin ?

let give you example with one page script.

To schedule the publication of posts on WordPress.
In addition to a control interface in the Dashboard that allows you to add and schedule posts easily.

  1. First, create a folder with the name of the new plugin, which I am a writer called “daily-posts-plugin”.
  2. Second, create a new PHP file named “daily_posts_plugin.php” and put the following code in it:
<?php
/*
Plugin Name: Daily Posts Plugin
Description: A plugin to publish daily posts with scheduling feature.
Version: 1.0
Author: Your Name
*/
// Add a new menu in the control panel
function daily_posts_menu() {
     add_menu_page(
         'Daily Posts',
         'Daily Posts',
         'manage_options',
         'daily-posts',
         'daily_posts_page',
         'dashicons-megaphone',
         20
     );
}
// Create a control interface page
function daily_posts_page() {
     // Check user permissions
     if (!current_user_can('manage_options')) {
         wp_die('You do not have sufficient permissions to access this page.');
     }
     // if the "Save" button is clicked
     if (isset($_POST['submit'])) {
         $post_content = sanitize_text_field($_POST['post_content']);
         $post_date = sanitize_text_field($_POST['post_date']);
         //Create the post
         $post_id = wp_insert_post(array(
             'post_title' => 'Daily Post',
             'post_content' => $post_content,
             'post_status' => 'future',
             'post_date' => $post_date
         ));
         if ($post_id) {
             echo '<div class="notice notice-success"><p>Post was saved successfully!</p></div>';
         } else {
             echo '<div class="notice notice-error"><p>An error occurred while saving the post. Please try again.</p></div>';
         }
     }
     ?>
     <div class="wrap">
         <h1>Add a daily post</h1>
         <form method="post" action="">
             <table class="form-table">
                 <tr>
                     <th scope="row"><label for="post_content">Post content</label></th>
                     <td><textarea id="post_content" name="post_content" rows="5" cols="50"></textarea></td>
                 </tr>
                 <tr>
                     <th scope="row"><label for="post_date">Published date</label></th>
                     <td><input type="date" id="post_date" name="post_date"></td>
                 </tr>
             </table>
             <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Save"></p>
         </form>
     </div>
     <?php
}
// Register the list and add the page to the control panel
add_action('admin_menu', 'daily_posts_menu');
Enter fullscreen mode Exit fullscreen mode
  1. We will compress the file with the extension . Zip We download it like any regular plugin from the WordPress panel.
  2. After that, we will activate our plugins from the WordPress control panel. After activating the add-on, the “Daily Posts” list will appear in the control panel. You can use it for your daily posts, You will be able to write the content of the post and specify the publication date. Then click the “Save” button to save the post and schedule it for publication on the specified date. Please note that you can customize the plugin according to your own needs, such as changing the plugin name and customizing the control panel. Or add other jobs... I hope any questions stay here and don't private anything unless necessary.

Image description
**part2 will be the Structure pages and Level.

DesignWordPressPlugin

WordPressPlugin

100MillionDEV #100MillionCC

100MillionCC

Top comments (0)