Changeset 3104343
- Timestamp:
- 06/19/2024 06:43:21 AM (7 weeks ago)
- Location:
- schedulify
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
schedulify/trunk/readme.txt
r3070243 r3104343 6 6 * Requires at least: 5.8 7 7 * Tested up to: 6.5 8 * Stable tag: 1.0. 48 * Stable tag: 1.0. 9 9 * License: GPLv2 or later 10 10 * License URI: http://www.gnu.org/licenses/gpl-2.0.html -
schedulify/trunk/schedulify.php
r3070239 r3104343 5 5 Author: WP Corner 6 6 Author URI: https://wpcorner.co 7 Version: 1.0. 47 Version: 1.0. 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 12 12 */ 13 13 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 16 if ( false === defined( 'ABSPATH' ) ) { 17 return; 18 } 19 20 //plugin basename for further reference 21 $nv_wpms_base_name = plugin_basename( __FILE__ ); 19 22 20 23 // Hook into WordPress 21 add_action( 'init', 'schedulify_init', 0);24 add_action(); 22 25 23 26 // 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);27 add_filter(); 28 add_filter(); 26 29 27 30 // Add activation link under the Posts menu 28 add_action( 'admin_menu', 'schedulify_add_activation_link_to_menu');31 add_action(); 29 32 30 33 // Add settings link 31 add_action( 'admin_menu', 'schedulify_add_settings_link_to_menu');34 add_action(); 32 35 33 36 // Add Cron Event Stats link 34 add_action( 'admin_menu', 'schedulify_add_cron_event_stats_link_to_menu');37 add_action(); 35 38 36 39 // Register settings 37 add_action( 'admin_init', 'schedulify_register_settings');40 add_action(); 38 41 39 42 /** 40 43 * Check timestamp from transient and publish all missed posts 41 44 */ 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()); 45 function 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() ); 52 54 53 55 global $wpdb; 54 56 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 () { 65 67 continue; 66 68 } 67 69 68 wp_publish_post( $scheduled_post_id);70 wp_publish_post(); 69 71 70 72 // Send Email Notification 71 if ( schedulify_get_email_notifications()) {72 schedulify_send_email_notification($scheduled_post_id);73 if () { 74 ); 73 75 } 74 76 } … … 80 82 * @param int $post_id 81 83 */ 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'), 84 function 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 */ 100 function 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 */ 113 function 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 */ 132 function nv_wpmsp_add_settings_link_to_menu() { 133 add_menu_page( 134 esc_html__( 'Schedulify', 'schedulify' ), 135 esc_html__( 'Schedulify', 'schedulify' ), 110 136 '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', 131 139 'dashicons-calendar' 132 140 ); 133 141 134 142 // 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(); 136 144 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__(), 140 148 'read', 141 149 'edit.php?post_status=future&post_type=post' … … 146 154 * Add Cron Event Stats link under the Schedulify menu 147 155 */ 148 function schedulify_add_cron_event_stats_link_to_menu() 149 { 150 if (!current_user_can('manage_options')) { 151 return; 152 } 153 156 function nv_wpmsp_add_cron_event_stats_link_to_menu() { 154 157 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__(), 158 161 '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' 161 164 ); 162 165 } … … 165 168 * Register plugin settings 166 169 */ 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'); 170 function 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' ); 173 175 } 174 176 … … 176 178 * Render settings page 177 179 */ 178 function schedulify_render_settings_page() 179 { 180 function nv_wpmsp_render_settings_page() { 180 181 // Check if the settings have been saved 181 if ( isset($_GET['settings-updated']) && $_GET['settings-updated']) {182 ?>182 if () { 183 ?> 183 184 <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> 185 186 <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> 187 188 </button> 188 189 </div> 189 <?php190 } 191 192 ?>190 <?php 191 } 192 193 ?> 193 194 <div class="wrap"> 194 <h1><?php esc_html_e( 'Schedulify Settings', 'schedulify'); ?></h1>195 <h1><?php esc_html_e(); ?></h1> 195 196 196 197 <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(); ?> 199 200 200 201 <table class="form-table"> 201 202 <tr valign="top"> 202 <th scope="row"><?php esc_html_e( 'Email Notifications', 'schedulify'); ?></th>203 <th scope="row"><?php esc_html_e(); ?></th> 203 204 <td> 204 205 <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(); ?> 207 208 </label> 208 <?php if ( get_option('schedulify_email_notifications', 1)) : ?>209 <?php if () : ?> 209 210 <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(); ?> 212 213 </label> 213 <input type="email" name=" schedulify_admin_email" value="<?php echo esc_attr(get_option('schedulify_admin_email')); ?>" />214 <input type="email" name="); ?>" /> 214 215 <?php endif; ?> 215 216 </td> 216 217 </tr> 217 218 <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> 219 220 <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(); ?> 222 223 </label> 223 <select name=" schedulify_custom_interval" id="schedulify_custom_interval">224 <select name="_custom_interval"> 224 225 <?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>'; 230 231 } 231 232 ?> … … 234 235 </tr> 235 236 <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> 237 238 <td> 238 239 <?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 ?> 244 245 <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(); ?> 247 248 </label> 248 249 <br> … … 252 253 </table> 253 254 254 <?php submit_button( esc_html__('Save Settings', 'schedulify')); ?>255 <?php submit_button(); ?> 255 256 </form> 256 257 </div> 257 <?php258 <?php 258 259 } 259 260 … … 261 262 * Render Cron Event Stats page 262 263 */ 263 function schedulify_render_cron_event_stats_page() 264 { 265 ?> 264 function nv_wpmsp_render_cron_event_stats_page() { 265 ?> 266 266 <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 --> 298 269 </div> 299 <?php270 <?php 300 271 } 301 272 … … 305 276 * @return int 306 277 */ 307 function schedulify_get_post_limit() 308 { 309 return apply_filters('schedulify_post_limit', get_option('schedulify_post_limit', 20)); 278 function nv_wpmsp_get_post_limit() { 279 return apply_filters( 'nv_wpmsp_post_limit', get_option( 'nv_wpmsp_post_limit', 20 ) ); 310 280 } 311 281 … … 315 285 * @return int 316 286 */ 317 function schedulify_get_interval() 318 { 319 return apply_filters('schedulify_interval', get_option('schedulify_custom_interval', 15) * MINUTE_IN_SECONDS); 287 function nv_wpmsp_get_interval() { 288 return apply_filters( 'nv_wpmsp_interval', get_option( 'nv_wpmsp_custom_interval', 15 ) * MINUTE_IN_SECONDS ); 320 289 } 321 290 … … 325 294 * @return bool 326 295 */ 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 } 296 function 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.