golden hour
/home/godaofbq/hardchambers.com/wp-content/plugins/wp-scheduled-posts-pro/includes/Scheduled
⬆️ Go Up
Upload
File/Folder
Size
Actions
Classic_Editor.php
17.28 KB
Del
OK
Manage.php
10.1 KB
Del
OK
Missed.php
1.15 KB
Del
OK
Published.php
27.92 KB
Del
OK
PublishedElementor.php
34.87 KB
Del
OK
Edit: Classic_Editor.php
<?php namespace WPSP_PRO\Scheduled; use WPSP\Helper as WPSPHelper; use WPSP_PRO; use WPSP_PRO\Helper; /** * Class Classic_Editor * * Handles advanced scheduling functionality for Classic_Editor editor posts. */ class Classic_Editor { /** * Classic_Editor constructor. * * Initiates hooks for advanced scheduling and content management. */ public function __construct() { add_action('current_screen', [ $this, 'classic_editor_actions' ] ); add_action('wpscp_pro_classic_advanced_schedule', [$this, 'wpscp_classic_pending_schedule']); add_filter( 'woocommerce_single_product_image_thumbnail_html', [ $this, 'modify_classic_thumbnail_for_product' ], 20, 2 ); add_filter('admin_post_thumbnail_html', [$this, 'custom_admin_post_thumbnail_html'], 10, 2); add_filter('wp_terms_checklist_args', [$this, 'selected_category_admin_checklist'], 10, 2); add_filter('acf/load_value', [$this, 'wpsp_acf_advanced_schedule'], 10, 3); } public function wpsp_acf_advanced_schedule($value, $post_id, $field) { $check_adv_schedule = get_post_meta(get_the_ID(), '_wpscppro_advance_schedule_date', true); if (empty($check_adv_schedule)) { return $value; } // Check if we are in the post editor if (is_admin() && get_current_screen()->base === 'post') { $get_meta = get_post_meta($post_id, 'wpscp_pending_schedule', true); if( !empty( $get_meta['acf'] ) ) { $acf_meta = $get_meta['acf']; $acf_meta_decode = json_decode($acf_meta); if( !empty( $acf_meta_decode->{$field['key']} ) ) { return $acf_meta_decode->{$field['key']}; } } } return $value; } public function classic_editor_actions( $screen ) { if ( is_object($screen) && method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) { return; } add_action('add_meta_boxes', array($this, 'advanced_schedule_metabox')); add_action('wp_insert_post_data', [$this, 'wpsp_advanced_schedule'], 10, 4); add_action('add_meta_boxes', [$this, 'update_classic_editor_data'] ); add_filter( 'wp_insert_post_data', [ $this, 'convert_object_to_array_post' ], 95, 2 ); if ( in_array( get_post_type($screen->post_type), Helper::get_settings('allow_post_types') ) ) { if (!use_block_editor_for_post_type($screen->post_type)) { add_filter('the_title', function($title, $id){ $screen = get_current_screen(); if (is_admin() && $screen && $screen->base === 'edit') { $post = get_post($id); $scheduled = (array) get_post_meta($post->ID, 'wpscp_pending_schedule', true); if( (isset($scheduled['status']) && $scheduled['status'] == 'future') || ( !empty( $scheduled['meta']['_wpscppro_advance_schedule'] ) ) || ( !empty( $scheduled['meta']['_wpscppro_advance_schedule_date'] ) ) ){ if ( 'publish' === $post->post_status ) { $title = !empty( $scheduled['post_title'] ) ? $scheduled['post_title'] : ''; } } } return $title; }, 10, 2); } } } public function convert_object_to_array_post($post, $postarr) { $post_id = null; // Check if $post is an object and an instance of WP_Post if (is_object($post) && $post instanceof \WP_Post) { $post_id = $post->ID; } // Check if $post is an array and contains the ID key elseif (is_array($post) && isset($post['ID'])) { $post_id = $post['ID']; } // If $post is neither an object nor an array with ID, return original $post else { return $post; } // Proceed with your existing logic if (in_array(get_post_type($post_id), Helper::get_settings('allow_post_types'))) { $get_post = get_post_meta($post_id, 'wpscp_pending_schedule', true); if (!empty($get_post)) { $obj_get_post = json_decode(json_encode($get_post)); $update_post = new \WP_Post($obj_get_post); return $update_post->to_array(); } } return $post; } /** * Checks and sets selected categories for the admin checklist based on post metadata. * * @param array $args Arguments for the category checklist. * @param int|null $post_id The ID of the post being checked. * @return array Modified arguments with selected categories set if applicable. */ public function selected_category_admin_checklist($args, $post_id = null) { $get_post = get_post_meta($post_id, 'wpscp_pending_schedule', true); if (!empty($get_post)) { $default_category_ids = $get_post['post_category']; if (!empty($default_category_ids)) { if (empty($args['selected_cats']) && $post_id === null) { $args['selected_cats'] = $default_category_ids; } elseif (empty($args['selected_cats'])) { $args['selected_cats'] = $default_category_ids; } } } return $args; } /** * Customizes the admin post thumbnail HTML for specific post types. * * @param string $content The existing post thumbnail HTML content. * @param int $post_id The ID of the post. * @return string Modified HTML content with custom thumbnail if applicable. */ public function custom_admin_post_thumbnail_html($content, $post_id) { global $post; if ($post && in_array(get_post_type($post), Helper::get_settings('allow_post_types'))) { $get_post = get_post_meta($post->ID, 'wpscp_pending_schedule', true); if (!empty($get_post)) { $obj_get_post = json_decode(json_encode($get_post)); $custom_image_url = Helper::get_post_thumbnail_url_by_id($post->_thumbnail_id); if (!empty($obj_get_post->custom_thumbnail)) { $custom_image_url = esc_url($obj_get_post->custom_thumbnail); } if (!empty($post->_thumbnail_id) && $post->_thumbnail_id != '-1') { $set_thumbnail_url = esc_url(admin_url('media-upload.php?post_id=' . $post->ID . '&type=image&TB_iframe=1&width=753&height=482')); $content = '<div id="postimagediv" class="postbox"> <div class="inside"> <p class="hide-if-no-js"> <a data-id="'.$post->_thumbnail_id.'" href="' . $set_thumbnail_url . '" id="set-post-thumbnail" aria-describedby="set-post-thumbnail-desc" class="thickbox"> <img src="' . esc_url($custom_image_url) . '" alt="Custom Thumbnail" /> </a> </p> <p class="hide-if-no-js howto" id="set-post-thumbnail-desc">Click the image to edit or update</p> <p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail">Remove featured image</a></p> <input type="hidden" id="_thumbnail_id" name="_thumbnail_id" value="' . $post->_thumbnail_id . '"> </div> </div>'; } } } return $content; } /** * Modifies the classic thumbnail for a product if advanced scheduling is set. * * @param string $image_html The existing thumbnail HTML. * @param int $thumbnail_id The ID of the thumbnail. * @return string Modified HTML content with custom thumbnail if applicable. */ public function modify_classic_thumbnail_for_product($image_html, $thumbnail_id) { $check_adv_schedule = get_post_meta(get_the_ID(), '_wpscppro_advance_schedule_date', true); if (empty($check_adv_schedule)) { return $image_html; } $check_thumbnail_id = get_post_meta(get_the_ID(), '_wpscppro_classic_advance_schedule_thumbnail', true); if (empty($check_thumbnail_id)) { return $image_html; } $image = wp_get_attachment_image(intval($check_thumbnail_id), 'full'); $html = '<div class="custom-post-thumbnail-wrapper">' . $image . '</div>'; return $html; } /** * Modifies the content of the classic thumbnail based on advanced scheduling. * * @param string $html The existing post thumbnail HTML content. * @param int $post_id The ID of the post. * @param int $post_thumbnail_id The ID of the post thumbnail. * @param string|array $size The size of the thumbnail. * @param array $attr Attributes for the thumbnail. * @return string Modified HTML content with custom thumbnail if applicable. */ public function modify_classic_thumbnail_content($html, $post_id, $post_thumbnail_id, $size, $attr) { $check_adv_schedule = get_post_meta(get_the_ID(), '_wpscppro_advance_schedule_date', true); $check_thumbnail_id = get_post_meta($post_id, '_wpscppro_classic_advance_schedule_thumbnail', true); if (empty($check_adv_schedule) && empty($check_thumbnail_id)) { return $html; } remove_filter('post_thumbnail_html', [$this, __FUNCTION__], 20); $image = wp_get_attachment_image(intval($check_thumbnail_id), 'full'); $html = '<div class="custom-post-thumbnail-wrapper">' . $image . '</div>'; return $html; } /** * Clears scheduled hook and deletes related post meta for pending advanced schedule. * * @param int $post_id The ID of the post. */ public function wpscp_classic_pending_schedule($post_id) { global $wpdb; $post_id_payload = array( 'post_id' => $post_id ); $get_post = get_post_meta($post_id, 'wpscp_pending_schedule', true); if( is_array( $get_post ) ) { $post_content = $get_post['post_content']; unset($get_post['post_content']); wp_update_post($get_post); $wpdb->update( $wpdb->posts, array('post_content' => $post_content), // Preserve raw content array('ID' => $post_id), array('%s'), // Data format array('%d') // Where condition format ); if( !empty( $get_post['acf'] ) ) { $acf_meta = json_decode($get_post['acf']); if( is_array($acf_meta) || is_object($acf_meta) ) { foreach ($acf_meta as $field_key => $value) { update_field($field_key, $value, $post_id); } } } set_post_thumbnail($post_id, $get_post['_thumbnail_id']); if( get_post_type( $post_id ) == 'product' ) { wp_set_post_terms($post_id, $get_post['post_category'], 'product_cat'); } } wp_clear_scheduled_hook( 'wpscp_pro_classic_advanced_schedule', $post_id_payload ); delete_post_meta($post_id, 'wpscp_pending_schedule'); delete_post_meta($post_id, '_wpscppro_advance_schedule'); delete_post_meta($post_id, '_wpscppro_advance_schedule_date'); delete_post_meta($post_id, '_wpscppro_classic_advance_schedule_thumbnail'); } public function update_classic_editor_data() { global $post; if ($post && in_array( get_post_type($post), Helper::get_settings('allow_post_types') ) ) { $get_post = get_post_meta($post->ID, 'wpscp_pending_schedule', true); if( !empty( $get_post ) ) { $obj_get_post = json_decode(json_encode($get_post)); $update_post = new \WP_Post($obj_get_post); $post = $update_post; return; } } } /** * Registers advanced scheduling metabox for eligible post types. */ public function advanced_schedule_metabox() { if( !WPSPHelper::is_user_allow() ) { return; } $allow_post_types = Helper::get_settings('allow_post_types'); $allow_post_types = (!empty($allow_post_types) ? $allow_post_types : array('post')); if (Helper::get_settings('is_delayed_schedule_active') == true && Helper::is_enable_classic_editor()) { add_meta_box('wpscp_pro_advanced_schedule_metabox', __('Advanced Schedule', 'wp-scheduled-posts-pro'), array($this, 'advanced_schedule_metabox_markup'), $allow_post_types, 'side', 'low'); } } /** * Handles advanced scheduling functionality on post save/update. * * @param int $post_id The ID of the post being saved/updated. * @param WP_Post $post The post object. * @param bool $update Whether this is an existing post being updated. */ public function wpsp_advanced_schedule($data, $postarr, $unsanitized_postarr, $update = null) { $action = isset( $_REQUEST['action'] ) ? sanitize_text_field($_REQUEST['action']) : ''; if( 'editpost' !== $action ) { return $data; } $post_id = $postarr['ID']; // Check if the current user can edit the post. if ( ! current_user_can( 'edit_post', $post_id ) ) { return; } // Check if this is an autosave or a revision. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $post_id ) ) { return; } $post_data = $_POST; $prev_post = get_post($post_id); $allow_post_types = \WPSP\Helper::get_settings('allow_post_types'); $post_types = (!empty($allow_post_types) ? $allow_post_types : array()); $published_post = get_post($post_id, ARRAY_A); $scheduled = get_post_meta($post_id, '_wpscppro_advance_schedule_date', true); $advanced_schedule_date = !empty($_POST['_wpscppro_advance_schedule_date']) ? sanitize_text_field($_POST['_wpscppro_advance_schedule_date']) : ''; $advanced_schedule_thumbnail = !empty($_POST['_thumbnail_id']) ? sanitize_text_field($_POST['_thumbnail_id']) : ''; if( get_post_type($post_id) == 'product' ) { $post_category = !empty($_POST['tax_input']['product_cat']) ? array_filter( $_POST['tax_input']['product_cat'], 'sanitize_text_field') : ''; }else{ $post_category = !empty($_POST['post_category']) ? array_filter($_POST['post_category'], 'sanitize_text_field') : ''; } $user = wp_get_current_user(); if (!empty($published_post) && empty($scheduled) && in_array($published_post['post_type'], $post_types) && in_array($published_post['post_status'], ['publish', 'private'])) { if (!empty($advanced_schedule_date)) { $this->set_advanced_schedule_cron($post_id, sanitize_text_field($advanced_schedule_date)); $data['meta']['_wpscppro_advance_schedule_date'] = sanitize_text_field($advanced_schedule_date); $data['ID'] = $post_id; $data['user_id'] = $user->ID; $data['_thumbnail_id'] = $advanced_schedule_thumbnail; $data['post_category'] = $post_category; $data['acf'] = json_encode($post_data['acf']); update_post_meta($post_id, 'wpscp_pending_schedule', $data); update_post_meta($post_id, '_wpscppro_advance_schedule_date', sanitize_text_field($advanced_schedule_date)); return $prev_post; } else { update_post_meta($post_id, '_wpscppro_advance_schedule', false); } } // update advanced schedule date else if (!empty($scheduled) && !empty($advanced_schedule_date)) { $this->set_advanced_schedule_cron($post_id, sanitize_text_field($advanced_schedule_date)); $data['meta']['_wpscppro_advance_schedule_date'] = sanitize_text_field($advanced_schedule_date); $data['ID'] = $post_id; $data['user_id'] = $user->ID; $data['_thumbnail_id'] = $advanced_schedule_thumbnail; $data['post_category'] = $post_category; $data['acf'] = json_encode($post_data['acf']); update_post_meta($post_id, 'wpscp_pending_schedule', $data); update_post_meta($post_id, '_wpscppro_advance_schedule_date', sanitize_text_field($advanced_schedule_date)); return $prev_post; } else { $post_id_payload = array('post_id' => $post_id); wp_clear_scheduled_hook('wpscp_pro_classic_advanced_schedule', $post_id_payload); update_post_meta( $post_id, '_wpscppro_advance_schedule_date', $advanced_schedule_date ); if( empty( $advanced_schedule_date ) ) { delete_post_meta( $post_id, '_wpscppro_advance_schedule'); } } return $data; } /** * Sets a cron job for advanced scheduling. * * @param int $post_id The ID of the post. * @param string $scheduled_date The scheduled date. */ public function set_advanced_schedule_cron($post_id, $scheduled_date) { if (empty($post_id)) { return; } $post_id_payload = array('post_id' => $post_id); $offset = get_option('gmt_offset'); $gmtOffset = (($offset == 0) ? $offset : (-get_option('gmt_offset'))); $new_advanced_schedule_date = date("Y-m-d H:i:s", strtotime("$gmtOffset hours", strtotime($scheduled_date))); $advanced_schedule_timestamp = strtotime($new_advanced_schedule_date); wp_clear_scheduled_hook('wpscp_pro_classic_advanced_schedule', $post_id_payload); wp_schedule_single_event($advanced_schedule_timestamp, 'wpscp_pro_classic_advanced_schedule', $post_id_payload); } /** * Retrieves the advanced schedule date for a post. * * @param int $post_id The ID of the post. * @return string|null The advanced schedule date or null if not set. */ public function wpsp_get_advance_schedule_date($post_id) { $wpsp_scheduled_data = get_post_meta( $post_id, 'wpscp_pending_schedule', true); if (!empty($wpsp_scheduled_data['meta']['_wpscppro_advance_schedule_date'])) { return $wpsp_scheduled_data['meta']['_wpscppro_advance_schedule_date']; } return get_post_meta($post_id, '_wpscppro_advance_schedule_date', true); } /** * Outputs markup for the advanced schedule metabox. * * @param object $data_object The data object. * @param object $box The metabox object. */ public function advanced_schedule_metabox_markup($data_object, $box) { global $post; wp_nonce_field(basename(__FILE__), 'wpscp_advanced_schedule_nonce'); $post_id = get_the_ID(); $advance_schedule_date = !empty( $this->wpsp_get_advance_schedule_date( $post_id ) ) ? $this->wpsp_get_advance_schedule_date( $post_id ) : ''; ?> <div class="wpscp-schedule-republish"> <div> <label> <?php esc_html_e('Advanced Schedule', 'wp-scheduled-posts-pro'); ?> <a href="https://wpdeveloper.com/docs/advanced-schedule-in-classic-editor/" class="info" target="_blank"><span class="dashicons dashicons-info"></span></a> <input type="text" id="wpscp_advanced_schedule_date" autocomplete="off" name="_wpscppro_advance_schedule_date" value="<?php print $advance_schedule_date ?>" placeholder="<?php esc_attr_e('Y/M/D H:M:S', 'wp-scheduled-posts-pro'); ?>" /> </label> </div> </div> <?php } }
Save