Plugin Directory

Changeset 3104343

Timestamp:
06/19/2024 06:43:21 AM (7 weeks ago)
Author:
lumiblog
Message:

Fixed minor issue experienced when activating the plugin.

Location:
schedulify
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • schedulify/trunk/readme.txt

    r3070243 r3104343  
    66* Requires at least: 5.8
    77* Tested up to: 6.5
    8 * Stable tag: 1.0.4
     8* Stable tag: 1.0.
    99* License: GPLv2 or later
    1010* License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • schedulify/trunk/schedulify.php

    r3070239 r3104343  
    55Author: WP Corner
    66Author URI: https://wpcorner.co
    7 Version: 1.0.4
     7Version: 1.0.
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1212*/
    1313
    14 // Exit if accessed directly
    15 if (!defined('ABSPATH')) exit;
    16 
    17 // Plugin basename for further reference
    18 $schedulify_base_name = plugin_basename(__FILE__);
     14
     15//bail if not WordPress path
     16if ( false === defined( 'ABSPATH' ) ) {
     17    return;
     18}
     19
     20//plugin basename for further reference
     21$nv_wpms_base_name = plugin_basename( __FILE__ );
    1922
    2023// Hook into WordPress
    21 add_action('init', 'schedulify_init', 0);
     24add_action();
    2225
    2326// Plugin Actions
    24 add_filter('plugin_action_links_' . $schedulify_base_name, 'schedulify_plugin_activation_link', 10, 1);
    25 add_filter('plugin_row_meta', 'schedulify_plugin_row_meta', 10, 2);
     27add_filter();
     28add_filter();
    2629
    2730// Add activation link under the Posts menu
    28 add_action('admin_menu', 'schedulify_add_activation_link_to_menu');
     31add_action();
    2932
    3033// Add settings link
    31 add_action('admin_menu', 'schedulify_add_settings_link_to_menu');
     34add_action();
    3235
    3336// Add Cron Event Stats link
    34 add_action('admin_menu', 'schedulify_add_cron_event_stats_link_to_menu');
     37add_action();
    3538
    3639// Register settings
    37 add_action('admin_init', 'schedulify_register_settings');
     40add_action();
    3841
    3942/**
    4043 * Check timestamp from transient and publish all missed posts
    4144 */
    42 function schedulify_init()
    43 {
    44     $last_scheduled_missed_time = get_transient('schedulify_scheduled_missed_time');
    45     $time = current_time('timestamp', 0);
    46 
    47     if (false !== $last_scheduled_missed_time && absint($last_scheduled_missed_time) > ($time - schedulify_get_interval())) {
    48         return;
    49     }
    50 
    51     set_transient('schedulify_scheduled_missed_time', $time, schedulify_get_interval());
     45function nv_wpmsp_init() {
     46    $last_scheduled_missed_time = get_transient( 'wp_scheduled_missed_time' );
     47    $time                       = current_time( 'timestamp', 0 );
     48
     49    if ( false !== $last_scheduled_missed_time && absint( $last_scheduled_missed_time ) > ( $time - nv_wpmsp_get_interval() ) ) {
     50        return;
     51    }
     52
     53    set_transient( 'wp_scheduled_missed_time', $time, nv_wpmsp_get_interval() );
    5254
    5355    global $wpdb;
    5456
    55     $sql_query = "SELECT ID FROM {$wpdb->posts} WHERE ( ( post_date > 0 && post_date <= %s ) ) AND post_status = 'future' LIMIT 0,%d";
    56     $sql = $wpdb->prepare($sql_query, current_time('mysql', 0), schedulify_get_post_limit());
    57     $scheduled_post_ids = $wpdb->get_col($sql);
    58 
    59     if (!count($scheduled_post_ids)) {
    60         return;
    61     }
    62 
    63     foreach ($scheduled_post_ids as $scheduled_post_id) {
    64         if (!$scheduled_post_id) {
     57    $sql_query = "SELECT ID FROM {$wpdb->posts} WHERE ( ( post_date > 0 && post_date <= %s ) ) AND post_status = 'future' LIMIT 0,%d";
     58    $sql );
     59    $scheduled_post_ids = $wpdb->get_col();
     60
     61    if () {
     62        return;
     63    }
     64
     65    foreach () {
     66        if () {
    6567            continue;
    6668        }
    6769
    68         wp_publish_post($scheduled_post_id);
     70        wp_publish_post();
    6971
    7072        // Send Email Notification
    71         if (schedulify_get_email_notifications()) {
    72             schedulify_send_email_notification($scheduled_post_id);
     73        if () {
     74            );
    7375        }
    7476    }
     
    8082 * @param int $post_id
    8183 */
    82 function schedulify_send_email_notification($post_id)
    83 {
    84     $admin_email = get_option('admin_email');
    85 
    86     $post = get_post($post_id);
    87     $post_title = $post ? $post->post_title : '';
    88 
    89     $subject = sprintf(esc_html__('Scheduled Post Published: %s', 'schedulify'), esc_html($post_title));
    90     $message = sprintf(esc_html__('The scheduled post "%s" (ID: %d) has been published.', 'schedulify'), esc_html($post_title), absint($post_id));
    91 
    92     wp_mail($admin_email, $subject, $message);
    93 }
    94 
    95 // ... (rest of the code remains the same) ...
    96 
    97 /**
    98  * Add activation link under the Posts menu
    99  */
    100 function schedulify_add_activation_link_to_menu()
    101 {
    102     if (!current_user_can('manage_options')) {
    103         return;
    104     }
    105 
    106     add_submenu_page(
    107         'edit.php?post_type=post',
    108         esc_html__('Schedulify', 'schedulify'),
    109         esc_html__('Schedulify', 'schedulify'),
     84function nv_wpmsp_send_email_notification( $post_id ) {
     85    $admin_email = get_option( 'admin_email' );
     86
     87    $subject = sprintf( esc_html__( 'Scheduled Post Published: #%d', 'schedulify' ), $post_id );
     88    $message = sprintf( esc_html__( 'The scheduled post #%d has been published.', 'schedulify' ), $post_id );
     89
     90    wp_mail( $admin_email, $subject, $message );
     91}
     92
     93/**
     94 * Add plugin activation link
     95 *
     96 * @param $links
     97 *
     98 * @return array
     99 */
     100function nv_wpmsp_plugin_activation_link( $links ) {
     101    $links[] = '<a href="edit.php?post_status=future&post_type=post">' . esc_html__( 'Scheduled Posts', 'schedulify' ) . '</a>';
     102
     103    return $links;
     104}
     105
     106/**
     107 * Add link in plugin row meta
     108 *
     109 * @param $links
     110 *
     111 * @return array
     112 */
     113function nv_wpmsp_plugin_row_meta( $links, $file ) {
     114    if ( false === is_admin() ) {
     115        return;
     116    }
     117
     118    if ( false === current_user_can( 'administrator' ) ) {
     119        return;
     120    }
     121
     122    if ( $file == plugin_basename( __FILE__ ) ) {
     123        $links[] = '<a href="https://github.com/lumumbapl/Schedulify/wiki/Documentation">' . esc_html__( 'Documentation', 'schedulify' ) . '</a>';
     124    }
     125
     126    return $links;
     127}
     128
     129/**
     130 * Add settings link under the Schedulify menu
     131 */
     132function nv_wpmsp_add_settings_link_to_menu() {
     133    add_menu_page(
     134        esc_html__( 'Schedulify', 'schedulify' ),
     135        esc_html__( 'Schedulify', 'schedulify' ),
    110136        'manage_options',
    111         'schedulify_activation_page',
    112         '__return_null'
    113     );
    114 }
    115 
    116 /**
    117  * Add settings link under the Schedulify menu
    118  */
    119 function schedulify_add_settings_link_to_menu()
    120 {
    121     if (!current_user_can('manage_options')) {
    122         return;
    123     }
    124 
    125     add_menu_page(
    126         esc_html__('Schedulify', 'schedulify'),
    127         esc_html__('Schedulify', 'schedulify'),
    128         'manage_options',
    129         'schedulify_settings_page',
    130         'schedulify_render_settings_page',
     137        'nv_wpmsp_settings_page',
     138        'nv_wpmsp_render_settings_page',
    131139        'dashicons-calendar'
    132140    );
    133141
    134142    // Move Scheduled Posts submenu
    135     remove_submenu_page('edit.php?post_status=future&post_type=post', 'edit.php?post_status=future&post_type=post');
     143    remove_submenu_page();
    136144    add_submenu_page(
    137         'schedulify_settings_page',
    138         esc_html__('Scheduled Posts', 'schedulify'),
    139         esc_html__('Scheduled Posts', 'schedulify'),
     145        '_settings_page',
     146        esc_html__(),
     147        esc_html__(),
    140148        'read',
    141149        'edit.php?post_status=future&post_type=post'
     
    146154 * Add Cron Event Stats link under the Schedulify menu
    147155 */
    148 function schedulify_add_cron_event_stats_link_to_menu()
    149 {
    150     if (!current_user_can('manage_options')) {
    151         return;
    152     }
    153 
     156function nv_wpmsp_add_cron_event_stats_link_to_menu() {
    154157    add_submenu_page(
    155         'schedulify_settings_page',
    156         esc_html__('Cron Event Stats', 'schedulify'),
    157         esc_html__('Cron Event Stats', 'schedulify'),
     158        '_settings_page',
     159        esc_html__(),
     160        esc_html__(),
    158161        'read',
    159         'schedulify_cron_event_stats_page',
    160         'schedulify_render_cron_event_stats_page'
     162        '_cron_event_stats_page',
     163        '_render_cron_event_stats_page'
    161164    );
    162165}
     
    165168 * Register plugin settings
    166169 */
    167 function schedulify_register_settings()
    168 {
    169     register_setting('schedulify_settings_group', 'schedulify_email_notifications', 'intval');
    170     register_setting('schedulify_settings_group', 'schedulify_admin_email', 'sanitize_email');
    171     register_setting('schedulify_settings_group', 'schedulify_custom_interval', 'intval');
    172     register_setting('schedulify_settings_group', 'schedulify_allowed_roles', 'schedulify_sanitize_roles');
     170function nv_wpmsp_register_settings() {
     171    register_setting( 'nv_wpmsp_settings_group', 'nv_wpmsp_email_notifications', 'intval' );
     172    register_setting( 'nv_wpmsp_settings_group', 'nv_wpmsp_admin_email', 'sanitize_email' );
     173    register_setting( 'nv_wpmsp_settings_group', 'nv_wpmsp_custom_interval', 'intval' );
     174    register_setting( 'nv_wpmsp_settings_group', 'nv_wpmsp_allowed_roles', 'nv_wpmsp_sanitize_roles' );
    173175}
    174176
     
    176178 * Render settings page
    177179 */
    178 function schedulify_render_settings_page()
    179 {
     180function nv_wpmsp_render_settings_page() {
    180181    // Check if the settings have been saved
    181     if (isset($_GET['settings-updated']) && $_GET['settings-updated']) {
    182 ?>
     182    if () {
     183?>
    183184        <div id="message" class="updated notice is-dismissible">
    184             <p><strong><?php esc_html_e('Settings saved.', 'schedulify'); ?></strong></p>
     185            <p><strong><?php esc_html_e(); ?></strong></p>
    185186            <button type="button" class="notice-dismiss">
    186                 <span class="screen-reader-text"><?php esc_html_e('Dismiss this notice.', 'schedulify'); ?></span>
     187                <span class="screen-reader-text"><?php esc_html_e(); ?></span>
    187188            </button>
    188189        </div>
    189 <?php
    190     }
    191 
    192 ?>
     190<?php
     191    }
     192
     193?>
    193194    <div class="wrap">
    194         <h1><?php esc_html_e('Schedulify Settings', 'schedulify'); ?></h1>
     195        <h1><?php esc_html_e(); ?></h1>
    195196
    196197        <form method="post" action="options.php">
    197             <?php settings_fields('schedulify_settings_group'); ?>
    198             <?php do_settings_sections('schedulify_settings_group'); ?>
     198            <?php settings_fields(); ?>
     199            <?php do_settings_sections(); ?>
    199200
    200201            <table class="form-table">
    201202                <tr valign="top">
    202                     <th scope="row"><?php esc_html_e('Email Notifications', 'schedulify'); ?></th>
     203                    <th scope="row"><?php esc_html_e(); ?></th>
    203204                    <td>
    204205                        <label>
    205                             <input type="checkbox" name="schedulify_email_notifications" value="1" <?php checked(get_option('schedulify_email_notifications', 1), 1); ?> />
    206                             <?php esc_html_e('Receive email notifications', 'schedulify'); ?>
     206                            <input type="checkbox" name="); ?> />
     207                            <?php esc_html_e(); ?>
    207208                        </label>
    208                         <?php if (get_option('schedulify_email_notifications', 1)) : ?>
     209                        <?php if () : ?>
    209210                            <br>
    210                             <label for="schedulify_admin_email">
    211                                 <?php esc_html_e('Email Address:', 'schedulify'); ?>
     211                            <label for="_admin_email">
     212                                <?php esc_html_e(); ?>
    212213                            </label>
    213                             <input type="email" name="schedulify_admin_email" value="<?php echo esc_attr(get_option('schedulify_admin_email')); ?>" />
     214                            <input type="email" name="); ?>" />
    214215                        <?php endif; ?>
    215216                    </td>
    216217                </tr>
    217218                <tr valign="top">
    218                     <th scope="row"><?php esc_html_e('Setting Custom Interval', 'schedulify'); ?></th>
     219                    <th scope="row"><?php esc_html_e(); ?></th>
    219220                    <td>
    220                         <label for="schedulify_custom_interval">
    221                             <?php esc_html_e('Choose Interval:', 'schedulify'); ?>
     221                        <label for="_custom_interval">
     222                            <?php esc_html_e(); ?>
    222223                        </label>
    223                         <select name="schedulify_custom_interval" id="schedulify_custom_interval">
     224                        <select name="_custom_interval">
    224225                            <?php
    225                             $selected_interval = get_option('schedulify_custom_interval', 15);
    226                             $intervals = array(5, 10, 15, 30, 60);
    227 
    228                             foreach ($intervals as $interval) {
    229                                 echo '<option value="' . esc_attr($interval) . '" ' . selected($selected_interval, $interval, false) . '>' . esc_html($interval) . ' ' . esc_html__('minutes', 'schedulify') . '</option>';
     226                            $selected_interval = get_option();
     227                            $intervals );
     228
     229                            foreach () {
     230                                echo '<option value="' . esc_attr() . '</option>';
    230231                            }
    231232                            ?>
     
    234235                </tr>
    235236                <tr valign="top">
    236                     <th scope="row"><?php esc_html_e('User Roles Access', 'schedulify'); ?></th>
     237                    <th scope="row"><?php esc_html_e(); ?></th>
    237238                    <td>
    238239                        <?php
    239                         $allowed_roles = get_option('schedulify_allowed_roles', array());
    240                         $all_roles = wp_roles()->get_names();
    241 
    242                         foreach ($all_roles as $role => $label) :
    243                         ?>
     240                        $allowed_roles = get_option();
     241                        $all_roles = wp_roles()->get_names();
     242
     243                        foreach () :
     244                        ?>
    244245                            <label>
    245                                 <input type="checkbox" name="schedulify_allowed_roles[]" value="<?php echo esc_attr($role); ?>" <?php checked(in_array($role, $allowed_roles), true); ?> />
    246                                 <?php echo esc_html($label); ?>
     246                                <input type="checkbox" name="); ?> />
     247                                <?php echo esc_html(); ?>
    247248                            </label>
    248249                            <br>
     
    252253            </table>
    253254
    254             <?php submit_button(esc_html__('Save Settings', 'schedulify')); ?>
     255            <?php submit_button(); ?>
    255256        </form>
    256257    </div>
    257 <?php
     258<?php
    258259}
    259260
     
    261262 * Render Cron Event Stats page
    262263 */
    263 function schedulify_render_cron_event_stats_page()
    264 {
    265 ?>
     264function nv_wpmsp_render_cron_event_stats_page() {
     265    ?>
    266266    <div class="wrap">
    267         <h1><?php esc_html_e('Cron Event Stats', 'schedulify'); ?></h1>
    268 
    269         <?php
    270         $last_scheduled_missed_time = get_transient('schedulify_scheduled_missed_time');
    271         $missed_posts_count = schedulify_get_missed_posts_count();
    272         $missed_posts = schedulify_get_missed_posts();
    273 
    274         if (false !== $last_scheduled_missed_time) :
    275         ?>
    276             <p><?php esc_html_e('Last Cron Run:', 'schedulify'); ?> <?php echo esc_html(date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $last_scheduled_missed_time)); ?></p>
    277         <?php endif; ?>
    278 
    279         <p><?php esc_html_e('Missed Scheduled Posts:', 'schedulify'); ?> <?php echo esc_html($missed_posts_count); ?></p>
    280 
    281         <?php if ($missed_posts_count > 0) : ?>
    282             <h2><?php esc_html_e('List of Missed Scheduled Posts:', 'schedulify'); ?></h2>
    283             <ul>
    284                 <?php foreach ($missed_posts as $missed_post) : ?>
    285                     <?php
    286                     $post_edit_link = get_edit_post_link($missed_post->ID);
    287                     $post_view_link = get_permalink($missed_post->ID);
    288                     ?>
    289                     <li>
    290                         <?php echo esc_html(get_the_title($missed_post->ID)); ?>
    291                         - <?php echo esc_html(date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($missed_post->post_date))); ?>
    292                         (<?php echo '<a href="' . esc_url($post_view_link) . '" target="_blank">' . esc_html__('View', 'schedulify') . '</a>'; ?> |
    293                             <?php echo '<a href="' . esc_url($post_edit_link) . '" target="_blank">' . esc_html__('Edit', 'schedulify') . '</a>'; ?>)
    294                     </li>
    295                 <?php endforeach; ?>
    296             </ul>
    297         <?php endif; ?>
     267        <h1><?php esc_html_e( 'Cron Event Stats', 'schedulify' ); ?></h1>
     268        <!-- Add your Cron Event Stats content here -->
    298269    </div>
    299 <?php
     270<?php
    300271}
    301272
     
    305276 * @return int
    306277 */
    307 function schedulify_get_post_limit()
    308 {
    309     return apply_filters('schedulify_post_limit', get_option('schedulify_post_limit', 20));
     278function nv_wpmsp_get_post_limit() {
     279    return apply_filters( 'nv_wpmsp_post_limit', get_option( 'nv_wpmsp_post_limit', 20 ) );
    310280}
    311281
     
    315285 * @return int
    316286 */
    317 function schedulify_get_interval()
    318 {
    319     return apply_filters('schedulify_interval', get_option('schedulify_custom_interval', 15) * MINUTE_IN_SECONDS);
     287function nv_wpmsp_get_interval() {
     288    return apply_filters( 'nv_wpmsp_interval', get_option( 'nv_wpmsp_custom_interval', 15 ) * MINUTE_IN_SECONDS );
    320289}
    321290
     
    325294 * @return bool
    326295 */
    327 function schedulify_get_email_notifications()
    328 {
    329     return apply_filters('schedulify_email_notifications', get_option('schedulify_email_notifications', true));
    330 }
    331 
    332 /**
    333  * Get the count of missed scheduled posts
    334  *
    335  * @return int
    336  */
    337 function schedulify_get_missed_posts_count()
    338 {
    339     global $wpdb;
    340 
    341     $sql_query = "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE ( ( post_date > 0 ) ) AND post_status = 'publish' AND post_type = 'post'";
    342     $missed_posts_count = $wpdb->get_var($sql_query);
    343 
    344     return $missed_posts_count;
    345 }
    346 
    347 /**
    348  * Get the list of missed scheduled posts
    349  *
    350  * @return array
    351  */
    352 function schedulify_get_missed_posts()
    353 {
    354     global $wpdb;
    355 
    356     $sql_query = "SELECT ID, post_date FROM {$wpdb->posts} WHERE ( ( post_date > 0 ) ) AND post_status = 'publish' AND post_type = 'post'";
    357     $missed_posts = $wpdb->get_results($sql_query);
    358 
    359     return $missed_posts;
    360 }
     296function nv_wpmsp_get_email_notifications() {
     297    return apply_filters( 'nv_wpmsp_email_notifications', get_option( 'nv_wpmsp_email_notifications', true ) );
     298}
Note: See TracChangeset for help on using the changeset viewer.