From 860b59e5185d677daaea14931caf9415632d81b1 Mon Sep 17 00:00:00 2001 From: Linkon Miyan Date: Thu, 5 Aug 2021 20:00:33 +0600 Subject: [PATCH 01/22] Added elementor update button sub menu and tab and ajax trigger. --- assets/js/elementor-editor.js | 26 ++++++++++++++++++ includes/Admin.php | 50 +++++++++++++++++++++++++++++++++++ includes/Assets.php | 4 +++ 3 files changed, 80 insertions(+) create mode 100644 assets/js/elementor-editor.js diff --git a/assets/js/elementor-editor.js b/assets/js/elementor-editor.js new file mode 100644 index 00000000..7ae0b5f8 --- /dev/null +++ b/assets/js/elementor-editor.js @@ -0,0 +1,26 @@ +(function ($) { + var wpsp_menu = $('#elementor-panel-footer-sub-menu-item-wpsp'), + modal = $('#schedulepress-elementor-modal'); + + $(window).on('load', function () { + $('.elementor-panel-footer-sub-menu-wrapper .elementor-panel-footer-sub-menu').append(wpsp_menu); + }); + + $(document).on('click', '#elementor-panel-footer-sub-menu-item-wpsp', function (e) { + e.preventDefault(); + modal.fadeIn(); + }).on('click', '.elementor-templates-modal__header__close > i, #schedulepress-elementor-modal', function (e) { + e.preventDefault(); + if (e.target === this) { + modal.fadeOut(); + } + }).on('click', 'button.wpsp-el-form-submit', function (e) { + e.preventDefault(); + var $form = modal.find('form'), + url = $form.attr('action'), + data = $form.serialize() + $.post(url, data, function (data) { + $(".wpsp-el-result").html(data); + }); + }) +})(jQuery); \ No newline at end of file diff --git a/includes/Admin.php b/includes/Admin.php index cc02192d..e024e032 100644 --- a/includes/Admin.php +++ b/includes/Admin.php @@ -16,6 +16,8 @@ public function __construct() $this->usage_tracker(); $this->load_dashboard_widgets(); $this->load_settings(); + + add_action('elementor/editor/footer', [$this, 'schedulepress_el_tab'], 100 ); } public function load_plugin_menu_pages() { @@ -185,4 +187,52 @@ public function load_settings() { new Admin\Settings(WPSP_SETTINGS_SLUG, WPSP_SETTINGS_NAME); } + + public function schedulepress_el_tab () { ?> + + + Date: Sun, 8 Aug 2021 19:12:34 +0600 Subject: [PATCH 02/22] Added Form fields and process schedule post action handler. --- assets/js/elementor-editor.js | 14 ++++- includes/Admin.php | 106 +++++++++++++++++++++++++++++++--- includes/Assets.php | 6 +- 3 files changed, 112 insertions(+), 14 deletions(-) diff --git a/assets/js/elementor-editor.js b/assets/js/elementor-editor.js index 7ae0b5f8..23b6b9da 100644 --- a/assets/js/elementor-editor.js +++ b/assets/js/elementor-editor.js @@ -4,6 +4,12 @@ $(window).on('load', function () { $('.elementor-panel-footer-sub-menu-wrapper .elementor-panel-footer-sub-menu').append(wpsp_menu); + $("#wpsp-schedule-datetime").flatpickr({ + enableTime: true, + dateFormat: "Y-m-dTH:i:S", + altInput: true, + altFormat: "F j, Y h:i K", + }); }); $(document).on('click', '#elementor-panel-footer-sub-menu-item-wpsp', function (e) { @@ -18,9 +24,13 @@ e.preventDefault(); var $form = modal.find('form'), url = $form.attr('action'), - data = $form.serialize() + data = $form.serialize(), + wpsp_submit_button = $('.wpsp-el-form-submit'); + + wpsp_submit_button.addClass('elementor-button-state'); $.post(url, data, function (data) { $(".wpsp-el-result").html(data); + wpsp_submit_button.removeClass('elementor-button-state'); }); - }) + }); })(jQuery); \ No newline at end of file diff --git a/includes/Admin.php b/includes/Admin.php index e024e032..2b4fbf80 100644 --- a/includes/Admin.php +++ b/includes/Admin.php @@ -17,7 +17,8 @@ public function __construct() $this->load_dashboard_widgets(); $this->load_settings(); - add_action('elementor/editor/footer', [$this, 'schedulepress_el_tab'], 100 ); + add_action( 'elementor/editor/footer', [ $this, 'schedulepress_el_tab' ], 100 ); + add_action( 'wp_ajax_wpsp_el_editor_form', [ $this, 'wpsp_el_tab_action' ] ); } public function load_plugin_menu_pages() { @@ -189,10 +190,56 @@ public function load_settings() } public function schedulepress_el_tab () { ?> + + + @@ -448,14 +442,38 @@ public function schedulepress_el_tab () { ?> +
+ + +
+ 0, - 'date' => '', - 'post_status' => 'future' + $offset = get_option( 'gmt_offset' ); + $offset = $offset == 0 ? 0 : ( 0 - $offset ); + $args = wp_parse_args( $_POST, [ + 'id' => 0, + 'date' => '', + 'republish_datetime' => '', + 'unpublish_datetime' => '', + 'post_status' => 'future' ] ); + if ( $offset !== 0 ) { + $date_gmt = date( "Y-m-d H:i:s", strtotime( $args['date'] ) + $offset * HOUR_IN_SECONDS ); + } else { + $date_gmt = $args['date']; + } + if ( empty( $args['id'] ) ) { wp_send_json_error( [ 'msg' => __( 'Your post id is empty', 'wp-scheduled-posts' ) @@ -465,10 +483,20 @@ public function wpsp_el_tab_action() { $id = wp_update_post( [ 'ID' => absint( $args['id'] ), 'post_date' => $args['date'], - 'post_date_gmt' => $args['date'], + 'post_date_gmt' => $date_gmt, 'post_status' => $args['post_status'] ] ); + if ( $this->pro_enabled ) { + if ( ! empty( $args['republish_datetime'] ) ) { + update_post_meta( $args['id'], '_wpscp_schedule_republish_date', sanitize_text_field( $args['republish_datetime'] ) ); + } + + if ( ! empty( $args['unpublish_datetime'] ) ) { + update_post_meta( $args['id'], '_wpscp_schedule_draft_date', sanitize_text_field( $args['unpublish_datetime'] ) ); + } + } + $status = get_post_status( $id ); if ( $status === 'future' ) { @@ -477,6 +505,8 @@ public function wpsp_el_tab_action() { $msg = __( 'Your post successfully published', 'wp-scheduled-posts' ); } + do_action( 'wpsp_el_action', absint( $args['id'] ), null, null ); + wp_send_json_success( [ 'id' => $id, 'status' => $status, From 45d864af8850473437a5571366665e7e6b7a9c7b Mon Sep 17 00:00:00 2001 From: Linkon Miyan Date: Wed, 25 Aug 2021 17:01:57 +0600 Subject: [PATCH 07/22] Fix Label color of 'Republish On' and 'Unpublish On' --- includes/Admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Admin.php b/includes/Admin.php index 1ab43ff7..9ecc6dc6 100644 --- a/includes/Admin.php +++ b/includes/Admin.php @@ -274,7 +274,7 @@ public function schedulepress_el_tab () { ?> margin-top: 15px; } - #schedulepress-elementor-modal .wpsp-pro-fields label > span { + #schedulepress-elementor-modal .wpsp-pro-fields:not(.wpsp-pro-activated) label > span { color: #9696af; } From 5e6fe1f404427895dd6bc32d864d157f08eca4c4 Mon Sep 17 00:00:00 2001 From: Linkon Miyan Date: Wed, 25 Aug 2021 17:12:43 +0600 Subject: [PATCH 08/22] Fixed -- When published a post by clicking "Publish future post immediately" the becomes "1970/01/01 at 12:00 am" --- includes/Admin.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/Admin.php b/includes/Admin.php index 9ecc6dc6..b61cf47e 100644 --- a/includes/Admin.php +++ b/includes/Admin.php @@ -468,6 +468,10 @@ public function wpsp_el_tab_action() { 'post_status' => 'future' ] ); + if ( empty( $args['date'] ) ) { + $args['date'] = date( 'Y-m-d H:i:s', current_time( 'U' ) ); + } + if ( $offset !== 0 ) { $date_gmt = date( "Y-m-d H:i:s", strtotime( $args['date'] ) + $offset * HOUR_IN_SECONDS ); } else { From dd926938c7279d1fbe646b18e8dc162a602a7412 Mon Sep 17 00:00:00 2001 From: Linkon Miyan Date: Wed, 25 Aug 2021 17:24:06 +0600 Subject: [PATCH 09/22] Fixed -- If a page is published via SchedulePress the page content doesn't save. It publishes a blank page. Same goes for if user changes something and publish/schedule it via SchedulePress it doesn't save the changes. --- assets/js/elementor-editor.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assets/js/elementor-editor.js b/assets/js/elementor-editor.js index f5e1cc9e..e25c5294 100644 --- a/assets/js/elementor-editor.js +++ b/assets/js/elementor-editor.js @@ -43,6 +43,8 @@ wpsp_submit_button = $('.wpsp-el-form-submit'), wpsp_el_result = $(".wpsp-el-result"); + $('#elementor-panel-saver-button-publish').trigger('click'); + wpsp_submit_button.addClass('elementor-button-state'); $.post(url, data, function (data) { wpsp_el_result.html(data.data.msg).slideDown(); From b6db89b4639f99f347b3ff4ed82e82ff5ac484b8 Mon Sep 17 00:00:00 2001 From: Linkon Miyan Date: Wed, 25 Aug 2021 17:45:48 +0600 Subject: [PATCH 10/22] Fixed -- Show Time Picker for 'Republish On' and 'Unpublish On' before picking any date like 'Publish On'. Otherwise, user will get confused --- includes/Admin.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/includes/Admin.php b/includes/Admin.php index b61cf47e..ee2da40e 100644 --- a/includes/Admin.php +++ b/includes/Admin.php @@ -366,16 +366,18 @@ public function schedulepress_el_tab () { ?>
From e84efaadd5aaa044b69fc73298be35f5db961a50 Mon Sep 17 00:00:00 2001 From: Linkon Miyan Date: Wed, 25 Aug 2021 18:17:50 +0600 Subject: [PATCH 11/22] Fixed -- 'Republish On' Time Picker going out of the screen for some devices --- includes/Admin.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/Admin.php b/includes/Admin.php index ee2da40e..8b0498b7 100644 --- a/includes/Admin.php +++ b/includes/Admin.php @@ -196,6 +196,8 @@ public function schedulepress_el_tab () { ?>