From 5407b1dbafdab2b6fafdb3067967bc491a81aa9c Mon Sep 17 00:00:00 2001 From: Jason Coleman Date: Thu, 26 Aug 2021 00:42:41 +1000 Subject: [PATCH 1/9] We can't do this yet. Need to disentangle our JS more first. --- includes/scripts.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/includes/scripts.php b/includes/scripts.php index baa6b1fa9..a48f1575d 100644 --- a/includes/scripts.php +++ b/includes/scripts.php @@ -94,11 +94,6 @@ function pmpro_enqueue_scripts() { * Enqueue admin JavaScript and CSS */ function pmpro_admin_enqueue_scripts() { - // Only enqueue PMPro admin scripts on our own pages. - if ( ! isset( $_GET['page'] ) || 0 !== strpos( $_GET['page'], 'pmpro' ) ) { - return; - } - // Admin JS wp_register_script( 'pmpro_admin', plugins_url( 'js/pmpro-admin.js', dirname(__FILE__) ), From a6244e4a254e2d9334049b87453b571eb72bf8a4 Mon Sep 17 00:00:00 2001 From: Jason Coleman Date: Thu, 26 Aug 2021 00:49:17 +1000 Subject: [PATCH 2/9] Prefixing the JS functions here --- js/pmpro-admin.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/js/pmpro-admin.js b/js/pmpro-admin.js index 3ac36cfef..0611db9ec 100644 --- a/js/pmpro-admin.js +++ b/js/pmpro-admin.js @@ -226,7 +226,7 @@ jQuery(document).ready(function($) { //get template data if (template) - getTemplate(template); + pmpro_get_template(template); else { $(".hide-while-loading").hide(); $(".controls").hide(); @@ -234,23 +234,23 @@ jQuery(document).ready(function($) { }); $("#submit_template_data").click(function() { - saveTemplate() + pmpro_save_template() }); $("#reset_template_data").click(function() { - resetTemplate(); + pmpro_reset_template(); }); $("#email_template_disable").click(function(e) { - disableTemplate(); + pmpro_disable_template(); }); $("#send_test_email").click(function(e) { - saveTemplate().done(setTimeout(function(){sendTestEmail();}, '1000')); + pmpro_save_template().done(setTimeout(function(){pmpro_send_test_email();}, '1000')); }); /* Functions */ - function getTemplate(template) { + function pmpro_get_template(template) { //hide stuff and show ajax spinner $(".hide-while-loading").hide(); @@ -301,11 +301,11 @@ jQuery(document).ready(function($) { // disable form disabled = template_data['disabled']; - toggleFormDisabled(disabled); + pmpro_toggle_form_disabled(disabled); }); } - function saveTemplate() { + function pmpro_save_template() { $("#submit_template_data").attr("disabled", true); $(".status").hide(); @@ -334,7 +334,7 @@ jQuery(document).ready(function($) { return $.Deferred().resolve(); } - function resetTemplate() { + function pmpro_reset_template() { var r = confirm('Are you sure? Your current template settings will be deleted permanently.'); @@ -354,7 +354,7 @@ jQuery(document).ready(function($) { return true; } - function disableTemplate() { + function pmpro_disable_template() { //update wp_options data = { @@ -388,11 +388,11 @@ jQuery(document).ready(function($) { disabled = response['status']; - toggleFormDisabled(disabled); + pmpro_toggle_form_disabled(disabled); }); } - function sendTestEmail() { + function pmpro_send_test_email() { //hide stuff and show ajax spinner $(".hide-while-loading").hide(); @@ -423,7 +423,7 @@ jQuery(document).ready(function($) { }) } - function toggleFormDisabled(disabled) { + function pmpro_toggle_form_disabled(disabled) { if(disabled == 'true') { $("#email_template_disable").prop('checked', true); $("#email_template_body").attr('readonly', 'readonly').attr('disabled', 'disabled'); From eff57563e1935f8c5026df3a5a402a17ef9b57bb Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Wed, 25 Aug 2021 09:57:53 -0500 Subject: [PATCH 3/9] Add information needed by the Blocks JS for levels --- blocks/blocks.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/blocks/blocks.php b/blocks/blocks.php index cfda721aa..b8fba34cc 100644 --- a/blocks/blocks.php +++ b/blocks/blocks.php @@ -65,6 +65,22 @@ function pmpro_block_editor_scripts() { PMPRO_VERSION ); + // Build out information needed by the blocks. + $all_levels = pmpro_getAllLevels( true, true ); + $all_level_values_and_labels = []; + + foreach ( $all_levels as $level ) { + $all_level_values_and_labels[] = [ + 'value' => $level->id, + 'label' => $level->name, + ]; + } + + wp_localize_script( 'pmpro-blocks-editor-js', 'pmpro', [ + 'all_levels' => $all_levels, + 'all_level_values_and_labels' => $all_level_values_and_labels, + ] ); + // Enqueue optional editor only styles. wp_enqueue_style( 'pmpro-blocks-editor-css', From f6d403797dcee9245a919bebde663c894ff54dbe Mon Sep 17 00:00:00 2001 From: Jason Coleman Date: Thu, 26 Aug 2021 01:01:40 +1000 Subject: [PATCH 4/9] Adding prefixes to email templates ids and names to avoid conflicts. --- adminpages/emailtemplates.php | 16 ++++++++-------- js/pmpro-admin.js | 36 +++++++++++++++++------------------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/adminpages/emailtemplates.php b/adminpages/emailtemplates.php index ad187ebaf..7198b6564 100644 --- a/adminpages/emailtemplates.php +++ b/adminpages/emailtemplates.php @@ -48,13 +48,13 @@ -

+

- @@ -63,18 +63,18 @@ - + - + - +
- +
@@ -97,10 +97,10 @@

- -

diff --git a/js/pmpro-admin.js b/js/pmpro-admin.js index 0611db9ec..120b9d6a1 100644 --- a/js/pmpro-admin.js +++ b/js/pmpro-admin.js @@ -211,7 +211,7 @@ jQuery(document).ready(function($) { /* Variables */ var template, disabled, $subject, $editor, $testemail; - $subject = $("#email_template_subject").closest("tr"); + $subject = $("#pmpro_email_template_subject").closest("tr"); $editor = $("#wp-email_template_body-wrap"); $testemail = $("#test_email_address").closest("tr"); @@ -233,15 +233,15 @@ jQuery(document).ready(function($) { } }); - $("#submit_template_data").click(function() { + $("#pmpro_submit_template_data").click(function() { pmpro_save_template() }); - $("#reset_template_data").click(function() { + $("#pmpro_reset_template_data").click(function() { pmpro_reset_template(); }); - $("#email_template_disable").click(function(e) { + $("#pmpro_email_template_disable").click(function(e) { pmpro_disable_template(); }); @@ -295,9 +295,9 @@ jQuery(document).ready(function($) { } // populate help text, subject, and body - $('#email_template_help_text').text(template_data['help_text']); - $('#email_template_subject').val(template_data['subject']); - $('#email_template_body').val(template_data['body']); + $('#pmpro_email_template_help_text').text(template_data['help_text']); + $('#pmpro_email_template_subject').val(template_data['subject']); + $('#pmpro_email_template_body').val(template_data['body']); // disable form disabled = template_data['disabled']; @@ -313,8 +313,8 @@ jQuery(document).ready(function($) { $data = { template: template, - subject: $("#email_template_subject").val(), - body: $("#email_template_body").val(), + subject: $("#pmpro_email_template_subject").val(), + body: $("#pmpro_email_template_body").val(), action: 'pmpro_email_templates_save_template_data', security: $('input[name=security]').val() }; @@ -347,8 +347,8 @@ jQuery(document).ready(function($) { }; $.post(ajaxurl, $data, function(response) { var template_data = $.parseJSON(response); - $('#email_template_subject').val(template_data['subject']); - $('#email_template_body').val(template_data['body']); + $('#pmpro_email_template_subject').val(template_data['subject']); + $('#pmpro_email_template_body').val(template_data['body']); }); return true; @@ -360,7 +360,7 @@ jQuery(document).ready(function($) { data = { template: template, action: 'pmpro_email_templates_disable_template', - disabled: $("#email_template_disable").is(":checked"), + disabled: $("#pmpro_email_template_disable").is(":checked"), security: $('input[name=security]').val() }; @@ -425,15 +425,15 @@ jQuery(document).ready(function($) { function pmpro_toggle_form_disabled(disabled) { if(disabled == 'true') { - $("#email_template_disable").prop('checked', true); - $("#email_template_body").attr('readonly', 'readonly').attr('disabled', 'disabled'); - $("#email_template_subject").attr('readonly', 'readonly').attr('disabled', 'disabled'); + $("#pmpro_email_template_disable").prop('checked', true); + $("#pmpro_email_template_body").attr('readonly', 'readonly').attr('disabled', 'disabled'); + $("#pmpro_email_template_subject").attr('readonly', 'readonly').attr('disabled', 'disabled'); $(".controls").hide(); } else { - $("#email_template_disable").prop('checked', false); - $("#email_template_body").removeAttr('readonly','readonly').removeAttr('disabled', 'disabled'); - $("#email_template_subject").removeAttr('readonly','readonly').removeAttr('disabled', 'disabled'); + $("#pmpro_email_template_disable").prop('checked', false); + $("#pmpro_email_template_body").removeAttr('readonly','readonly').removeAttr('disabled', 'disabled'); + $("#pmpro_email_template_subject").removeAttr('readonly','readonly').removeAttr('disabled', 'disabled'); $(".controls").show(); } From 2d14f3dca12f5d22974ce4b90a1fad193f57c512 Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Wed, 25 Aug 2021 10:04:53 -0500 Subject: [PATCH 5/9] Register and then enqueue after adding var --- blocks/blocks.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/blocks/blocks.php b/blocks/blocks.php index b8fba34cc..84dcadc1c 100644 --- a/blocks/blocks.php +++ b/blocks/blocks.php @@ -58,10 +58,18 @@ function pmpro_place_blocks_in_panel( $categories, $post_or_context ) { */ function pmpro_block_editor_scripts() { // Enqueue the bundled block JS file. - wp_enqueue_script( + wp_register_script( 'pmpro-blocks-editor-js', plugins_url( 'js/blocks.build.js', PMPRO_BASE_FILE ), - array('wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-api', 'wp-block-editor', 'pmpro_admin'), + [ + 'wp-i18n', + 'wp-element', + 'wp-blocks', + 'wp-components', + 'wp-api', + 'wp-block-editor', + 'pmpro_admin', + ], PMPRO_VERSION ); @@ -81,6 +89,8 @@ function pmpro_block_editor_scripts() { 'all_level_values_and_labels' => $all_level_values_and_labels, ] ); + wp_enqueue_script( 'pmpro-blocks-editor-js' ); + // Enqueue optional editor only styles. wp_enqueue_style( 'pmpro-blocks-editor-css', From 84aaa7879d5792f1d34040310d53e1d87f1328be Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Wed, 25 Aug 2021 10:32:58 -0500 Subject: [PATCH 6/9] Adjust code so it always registers but only enqueues if it is on our page --- includes/scripts.php | 98 ++++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 39 deletions(-) diff --git a/includes/scripts.php b/includes/scripts.php index a48f1575d..58642cf2f 100644 --- a/includes/scripts.php +++ b/includes/scripts.php @@ -94,43 +94,63 @@ function pmpro_enqueue_scripts() { * Enqueue admin JavaScript and CSS */ function pmpro_admin_enqueue_scripts() { - // Admin JS - wp_register_script( 'pmpro_admin', - plugins_url( 'js/pmpro-admin.js', dirname(__FILE__) ), - array( 'jquery', 'jquery-ui-sortable' ), - PMPRO_VERSION ); - $all_levels = pmpro_getAllLevels( true, true ); - $all_level_values_and_labels = array(); - foreach( $all_levels as $level ) { - $all_level_values_and_labels[] = array( 'value' => $level->id, 'label' => $level->name ); - } - wp_localize_script( 'pmpro_admin', 'pmpro', array( - 'all_levels' => $all_levels, - 'all_level_values_and_labels' => $all_level_values_and_labels - )); - wp_enqueue_script( 'pmpro_admin' ); - - // Admin CSS - $admin_css_rtl = false; - if(file_exists(get_stylesheet_directory() . "/paid-memberships-pro/css/admin.css")) { - $admin_css = get_stylesheet_directory_uri() . "/paid-memberships-pro/css/admin.css"; - if( is_rtl() && file_exists(get_stylesheet_directory() . "/paid-memberships-pro/css/admin-rtl.css") ) { - $admin_css_rtl = get_stylesheet_directory_uri() . "/paid-memberships-pro/css/admin-rtl.css"; - } - } elseif(file_exists(get_template_directory() . "/paid-memberships-pro/admin.css")) { - $admin_css = get_template_directory_uri() . "/paid-memberships-pro/admin.css"; - if( is_rtl() && file_exists(get_template_directory() . "/paid-memberships-pro/css/admin-rtl.css") ) { - $admin_css_rtl = get_template_directory_uri() . "/paid-memberships-pro/css/admin-rtl.css"; - } - } else { - $admin_css = plugins_url('css/admin.css',dirname(__FILE__) ); - if( is_rtl() ) { - $admin_css_rtl = plugins_url('css/admin-rtl.css',dirname(__FILE__) ); - } - } - wp_enqueue_style('pmpro_admin', $admin_css, array(), PMPRO_VERSION, "screen"); - if( $admin_css_rtl ) { - wp_enqueue_style('pmpro_admin_rtl', $admin_css_rtl, array(), PMPRO_VERSION, "screen"); - } + // Admin JS + wp_register_script( 'pmpro_admin', plugins_url( 'js/pmpro-admin.js', __DIR__ ), [ + 'jquery', + 'jquery-ui-sortable', + ], PMPRO_VERSION ); + + $all_levels = pmpro_getAllLevels( true, true ); + $all_level_values_and_labels = []; + + foreach ( $all_levels as $level ) { + $all_level_values_and_labels[] = [ + 'value' => $level->id, + 'label' => $level->name, + ]; + } + + wp_localize_script( 'pmpro_admin', 'pmpro', [ + 'all_levels' => $all_levels, + 'all_level_values_and_labels' => $all_level_values_and_labels, + ] ); + + // Admin CSS + $admin_css_rtl = false; + + if ( file_exists( get_stylesheet_directory() . '/paid-memberships-pro/css/admin.css' ) ) { + $admin_css = get_stylesheet_directory_uri() . '/paid-memberships-pro/css/admin.css'; + + if ( is_rtl() && file_exists( get_stylesheet_directory() . '/paid-memberships-pro/css/admin-rtl.css' ) ) { + $admin_css_rtl = get_stylesheet_directory_uri() . '/paid-memberships-pro/css/admin-rtl.css'; + } + } elseif ( file_exists( get_template_directory() . '/paid-memberships-pro/admin.css' ) ) { + $admin_css = get_template_directory_uri() . '/paid-memberships-pro/admin.css'; + + if ( is_rtl() && file_exists( get_template_directory() . '/paid-memberships-pro/css/admin-rtl.css' ) ) { + $admin_css_rtl = get_template_directory_uri() . '/paid-memberships-pro/css/admin-rtl.css'; + } + } else { + $admin_css = plugins_url( 'css/admin.css', __DIR__ ); + + if ( is_rtl() ) { + $admin_css_rtl = plugins_url( 'css/admin-rtl.css', __DIR__ ); + } + } + + wp_register_style( 'pmpro_admin', $admin_css, [], PMPRO_VERSION, 'screen' ); + + if ( $admin_css_rtl ) { + wp_register_style( 'pmpro_admin_rtl', $admin_css_rtl, [], PMPRO_VERSION, 'screen' ); + } + + // Only enqueue PMPro admin scripts on our own pages. + if ( ! isset( $_GET['page'] ) || 0 !== strpos( $_GET['page'], 'pmpro' ) ) { + return; + } + + wp_enqueue_script( 'pmpro_admin' ); + wp_enqueue_style( 'pmpro_admin' ); + wp_enqueue_style( 'pmpro_admin_rtl' ); } -add_action( 'admin_enqueue_scripts', 'pmpro_admin_enqueue_scripts' ); \ No newline at end of file +add_action( 'admin_enqueue_scripts', 'pmpro_admin_enqueue_scripts' ); From 4eb24c9a654b642fe6d32abb76b9a257ce16e410 Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Wed, 25 Aug 2021 10:40:05 -0500 Subject: [PATCH 7/9] Enqueue and follow up on this later --- blocks/blocks.php | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/blocks/blocks.php b/blocks/blocks.php index 84dcadc1c..bad8547eb 100644 --- a/blocks/blocks.php +++ b/blocks/blocks.php @@ -58,7 +58,7 @@ function pmpro_place_blocks_in_panel( $categories, $post_or_context ) { */ function pmpro_block_editor_scripts() { // Enqueue the bundled block JS file. - wp_register_script( + wp_enqueue_script( 'pmpro-blocks-editor-js', plugins_url( 'js/blocks.build.js', PMPRO_BASE_FILE ), [ @@ -73,24 +73,6 @@ function pmpro_block_editor_scripts() { PMPRO_VERSION ); - // Build out information needed by the blocks. - $all_levels = pmpro_getAllLevels( true, true ); - $all_level_values_and_labels = []; - - foreach ( $all_levels as $level ) { - $all_level_values_and_labels[] = [ - 'value' => $level->id, - 'label' => $level->name, - ]; - } - - wp_localize_script( 'pmpro-blocks-editor-js', 'pmpro', [ - 'all_levels' => $all_levels, - 'all_level_values_and_labels' => $all_level_values_and_labels, - ] ); - - wp_enqueue_script( 'pmpro-blocks-editor-js' ); - // Enqueue optional editor only styles. wp_enqueue_style( 'pmpro-blocks-editor-css', From f2d2c8a496991cd4757519b8b9f0081d6520bb4a Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Wed, 25 Aug 2021 10:46:01 -0500 Subject: [PATCH 8/9] Only enqueue if rtl --- includes/scripts.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/scripts.php b/includes/scripts.php index 58642cf2f..f53408ae3 100644 --- a/includes/scripts.php +++ b/includes/scripts.php @@ -139,10 +139,7 @@ function pmpro_admin_enqueue_scripts() { } wp_register_style( 'pmpro_admin', $admin_css, [], PMPRO_VERSION, 'screen' ); - - if ( $admin_css_rtl ) { - wp_register_style( 'pmpro_admin_rtl', $admin_css_rtl, [], PMPRO_VERSION, 'screen' ); - } + wp_register_style( 'pmpro_admin_rtl', $admin_css_rtl, [], PMPRO_VERSION, 'screen' ); // Only enqueue PMPro admin scripts on our own pages. if ( ! isset( $_GET['page'] ) || 0 !== strpos( $_GET['page'], 'pmpro' ) ) { @@ -151,6 +148,9 @@ function pmpro_admin_enqueue_scripts() { wp_enqueue_script( 'pmpro_admin' ); wp_enqueue_style( 'pmpro_admin' ); - wp_enqueue_style( 'pmpro_admin_rtl' ); + + if ( $admin_css_rtl ) { + wp_enqueue_style( 'pmpro_admin_rtl' ); + } } add_action( 'admin_enqueue_scripts', 'pmpro_admin_enqueue_scripts' ); From 793e7d4ed42edba790fe8f48a0b47f0ae3f269c9 Mon Sep 17 00:00:00 2001 From: Jason Coleman Date: Thu, 26 Aug 2021 01:52:15 +1000 Subject: [PATCH 9/9] version and changelog updates --- CHANGELOG.txt | 4 ++++ paid-memberships-pro.php | 4 ++-- readme.txt | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 3d4c9dd1f..11deae373 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,8 @@ == Changelog == += 2.6.1.1 - 2021-08-25 = +* BUG FIX: Fixed issue with PMPro blocks not showing up in the block editor. +* REFACTOR: Some JS functions and element IDs and names have been prefixed with pmpro_ to avoid conflicts. + = 2.6.1 - 2021-08-24 = * SECURITY: Added capability checks to further tighten security around email template settings. (@ideadude, @sc0ttkclark) * SECURITY: Added a pmpro_kses function and using that to sanitize email template bodies and all email bodies before sending. (@ideadude, @sc0ttkclark) diff --git a/paid-memberships-pro.php b/paid-memberships-pro.php index e6b90b3fa..74b2ead49 100644 --- a/paid-memberships-pro.php +++ b/paid-memberships-pro.php @@ -3,7 +3,7 @@ * Plugin Name: Paid Memberships Pro * Plugin URI: https://www.paidmembershipspro.com * Description: The most complete member management and membership subscriptions plugin for WordPress. - * Version: 2.6.1 + * Version: 2.6.1.1 * Author: Stranger Studios * Author URI: https://www.strangerstudios.com * Text Domain: paid-memberships-pro @@ -16,7 +16,7 @@ */ // version constant -define( 'PMPRO_VERSION', '2.6.1' ); +define( 'PMPRO_VERSION', '2.6.1.1' ); define( 'PMPRO_USER_AGENT', 'Paid Memberships Pro v' . PMPRO_VERSION . '; ' . site_url() ); define( 'PMPRO_MIN_PHP_VERSION', '5.6' ); diff --git a/readme.txt b/readme.txt index 28cbfac7e..e8fd4eae0 100644 --- a/readme.txt +++ b/readme.txt @@ -155,6 +155,10 @@ Not sure? You can find out by doing a bit a research. 9. Membership Account page, display all sections or show specific sections using shortcode attributes. == Changelog == += 2.6.1.1 - 2021-08-25 = +* BUG FIX: Fixed issue with PMPro blocks not showing up in the block editor. +* REFACTOR: Some JS functions and element IDs and names have been prefixed with pmpro_ to avoid conflicts. + = 2.6.1 - 2021-08-24 = * SECURITY: Added capability checks to further tighten security around email template settings. (@ideadude, @sc0ttkclark) * SECURITY: Added a pmpro_kses function and using that to sanitize email template bodies and all email bodies before sending. (@ideadude, @sc0ttkclark)