From ab35c671c4aa1cd877bec5236a8f87a691a6f8f6 Mon Sep 17 00:00:00 2001
From: Paul Kevan
Date: Fri, 22 Nov 2024 08:24:16 +0000
Subject: [PATCH 01/15] Start refactoring
---
.../wp-content/plugins/camptix/camptix.php | 469 +----------------
.../camptix/inc/class-camptix-admin.php | 480 ++++++++++++++++++
2 files changed, 484 insertions(+), 465 deletions(-)
create mode 100644 public_html/wp-content/plugins/camptix/inc/class-camptix-admin.php
diff --git a/public_html/wp-content/plugins/camptix/camptix.php b/public_html/wp-content/plugins/camptix/camptix.php
index 4182556df5..ba55fd45b8 100644
--- a/public_html/wp-content/plugins/camptix/camptix.php
+++ b/public_html/wp-content/plugins/camptix/camptix.php
@@ -67,6 +67,7 @@ function __construct() {
require( dirname( __FILE__ ) . '/inc/class-camptix-addon.php' );
require( dirname( __FILE__ ) . '/inc/class-camptix-payment-method.php' );
+ require( dirname( __FILE__ ) . '/inc/class-camptix-admin.php' );
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once( dirname( __FILE__ ) . '/inc/class-wp-cli-commands.php' );
@@ -121,9 +122,6 @@ function init() {
// Stuff that might need to redirect, thus not in [camptix] shortcode.
add_action( 'template_redirect', array( $this, 'template_redirect' ), 9 ); // earlier than the others.
- add_action( 'admin_init', array( $this, 'admin_init' ) );
- add_action( 'admin_menu', array( $this, 'admin_menu' ) );
- add_action( 'admin_head', array( $this, 'admin_menu_fix' ) );
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
// Handle meta for our post types.
@@ -150,7 +148,6 @@ function init() {
$this->add_resend_notices();
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
// Sort of admin_init but on the Tickets > Tools page only.
add_action( 'load-tix_ticket_page_camptix_tools', array( $this, 'summarize_extra_fields' ) );
@@ -448,7 +445,7 @@ function notify_shortcode_ticket_url( $atts ) {
* grabs all the available tickets questions and adds them to Summarize.
*/
function summarize_extra_fields() {
- if ( 'summarize' != $this->get_tools_section() )
+ if ( 'summarize' != Camptix_Admin::get_tools_section() )
return;
// Adds all questions to Summarize and register the callback that counts all the things.
@@ -510,59 +507,6 @@ function enqueue_scripts() {
) );
}
- function admin_enqueue_scripts() {
- global $wp_query;
-
- if ( ! $wp_query->query_vars ) { // only on singular admin pages
- if ( 'tix_ticket' == get_post_type() || 'tix_coupon' == get_post_type() ) {
- }
- }
-
- // Let's see whether to include admin.css and admin.js
- if ( is_admin() ) {
- $screen = get_current_screen();
- $post_types = array( 'tix_ticket', 'tix_coupon', 'tix_email', 'tix_attendee' );
- $pages = array( 'camptix_options', 'camptix_tools' );
- $screen_ids = array( 'dashboard' );
- if (
- ( in_array( get_post_type(), $post_types ) ) ||
- ( in_array( $screen->id, $screen_ids ) ) ||
- ( isset( $_REQUEST['post_type'] ) && in_array( $_REQUEST['post_type'], $post_types ) ) ||
- ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $pages ) )
- ) {
- wp_enqueue_script( 'jquery-ui-datepicker' );
- wp_enqueue_style(
- 'jquery-ui',
- plugins_url( '/external/jquery-ui.css', __FILE__ ),
- array(),
- filemtime( __DIR__ . '/external/jquery-ui.css' )
- );
-
- wp_enqueue_style(
- 'camptix-admin',
- plugins_url( '/admin.css', __FILE__ ),
- array(),
- filemtime( __DIR__ . '/admin.css' )
- );
-
- wp_enqueue_script(
- 'camptix-admin',
- plugins_url( '/admin.js', __FILE__ ),
- array( 'jquery', 'jquery-ui-datepicker', 'backbone' ),
- filemtime( __DIR__ . '/admin.js' )
- );
-
- wp_dequeue_script( 'autosave' );
- }
- }
-
- $screen = get_current_screen();
- if ( 'tix_ticket_page_camptix_options' == $screen->id ) {
- wp_enqueue_script( 'jquery-ui-datepicker' );
- wp_enqueue_style( 'jquery-ui', plugins_url( '/external/jquery-ui.css', __FILE__ ), array(), $this->version );
- }
- }
-
/**
* Filters column fields for our new post types, adds extra columns
* and registers callback actions to render column callback.
@@ -1555,121 +1499,7 @@ protected function run_upgrade_parts( $from ) {
return $this->version;
}
- /**
- * Runs during admin_init, mainly for Settings API things.
- */
- function admin_init() {
- register_setting( 'camptix_options', 'camptix_options', array( $this, 'validate_options' ) );
-
- // Add settings fields
- $this->menu_setup_controls();
-
- // Let's add some help tabs.
- require_once dirname( __FILE__ ) . '/help.php';
- }
-
- function menu_setup_controls() {
- wp_enqueue_script( 'jquery-ui' );
- $section = $this->get_setup_section();
-
- add_action( 'admin_notices', array( $this, 'admin_notice_supported_currencies' ) );
-
- switch ( $section ) {
- case 'general':
- add_settings_section( 'general', __( 'General Configuration', 'wordcamporg' ), array( $this, 'menu_setup_section_general' ), 'camptix_options' );
- $this->add_settings_field_helper( 'event_name', __( 'Event Name', 'wordcamporg' ), 'field_text' );
- $this->add_settings_field_helper( 'currency', __( 'Currency', 'wordcamporg' ), 'field_currency' );
-
- $this->add_settings_field_helper( 'refunds_enabled', __( 'Enable Refunds', 'wordcamporg' ), 'field_enable_refunds', false,
- __( "This will allows your customers to refund their tickets purchase by filling out a simple refund form.", 'wordcamporg' )
- );
-
- break;
- case 'payment':
- foreach ( $this->get_available_payment_methods() as $key => $payment_method ) {
- $payment_method_obj = $this->get_payment_method_by_id( $key );
-
- add_settings_section( 'payment_' . $key, $payment_method_obj->name, array( $payment_method_obj, '_camptix_settings_section_callback' ), 'camptix_options' );
- add_settings_field( 'payment_method_' . $key . '_enabled', __( 'Enabled', 'wordcamporg' ), array( $payment_method_obj, '_camptix_settings_enabled_callback' ), 'camptix_options', 'payment_' . $key, array(
- 'name' => "camptix_options[payment_methods][{$key}]",
- 'value' => isset( $this->options['payment_methods'][$key] ) ? (bool) $this->options['payment_methods'][ $key ] : false,
- ) );
-
- $payment_method_obj->payment_settings_fields();
- }
- break;
- case 'email-templates':
- add_settings_section( 'general', __( 'E-mail Templates', 'wordcamporg' ), array( $this, 'menu_setup_section_email_templates' ), 'camptix_options' );
- $this->add_settings_field_helper( 'email_template_single_purchase', __( 'Single purchase', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_multiple_purchase', __( 'Multiple purchase', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_multiple_purchase_receipt', __( 'Multiple purchase (receipt)', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_pending_succeeded', __( 'Pending Payment Succeeded', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_pending_failed', __( 'Pending Payment Failed', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_single_refund', __( 'Single Refund', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_multiple_refund', __( 'Multiple Refund', 'wordcamporg' ), 'field_textarea' );
-
- foreach ( apply_filters( 'camptix_custom_email_templates', array() ) as $key => $template ) {
- $this->add_settings_field_helper( $key, $template['title'], $template['callback_method'] );
- }
-
- // Add a reset templates button
- add_action( 'camptix_setup_buttons', array( $this, 'setup_buttons_reset_templates' ) );
- break;
- case 'beta':
-
- if ( ! $this->beta_features_enabled )
- break;
-
- add_settings_section( 'general', __( 'Beta Features', 'wordcamporg' ), array( $this, 'menu_setup_section_beta' ), 'camptix_options' );
-
- $this->add_settings_field_helper( 'reservations_enabled', __( 'Enable Reservations', 'wordcamporg' ), 'field_yesno', false,
- __( "Reservations is a way to make sure that a certain group of people, can always purchase their tickets, even if you sell out fast.", 'wordcamporg' )
- );
-
- if ( current_user_can( $this->caps['refund_all'] ) ) {
- $this->add_settings_field_helper( 'refund_all_enabled', __( 'Enable Refund All', 'wordcamporg' ), 'field_yesno', false,
- __( "Allows to refund all purchased tickets by an admin via the Tools menu.", 'wordcamporg' )
- );
- }
-
- $this->add_settings_field_helper( 'archived', __( 'Archived Event', 'wordcamporg' ), 'field_yesno', false,
- __( "Archived events are read-only.", 'wordcamporg' )
- );
- break;
- default:
- do_action( 'camptix_menu_setup_controls', $section );
- break;
- }
- }
-
- function menu_setup_section_beta() {
- echo '
' . __( 'Beta features are things that are being worked on in CampTix, but are not quite finished yet. You can try them out, but we do not recommend doing that in a live environment on a real event. If you have any kind of feedback on any of the beta features, please let us know.', 'wordcamporg' ) . '
';
- }
/**
* I don't like repeating code, so here's a helper for simple fields.
@@ -2026,254 +1856,6 @@ function format_name_string( $name_string, $given_name, $surname ) {
return $name_string;
}
- /**
- * Oh the holy admin menu!
- */
- function admin_menu() {
- add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Tools', 'wordcamporg' ), __( 'Tools', 'wordcamporg' ), $this->caps['manage_tools'], 'camptix_tools', array( $this, 'menu_tools' ) );
- add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Setup', 'wordcamporg' ), __( 'Setup', 'wordcamporg' ), $this->caps['manage_options'], 'camptix_options', array( $this, 'menu_setup' ) );
- remove_submenu_page( 'edit.php?post_type=tix_ticket', 'post-new.php?post_type=tix_ticket' );
- }
-
- /**
- * When squeezing several custom post types under one top-level menu item, WordPress
- * tends to get confused which menu item is currently active, especially around post-new.php.
- * This function runs during admin_head and hacks into some of the global variables that are
- * used to construct the menu.
- */
- function admin_menu_fix() {
- global $self, $parent_file, $submenu_file, $plugin_page, $pagenow, $typenow;
-
- // Make sure Coupons is selected when adding a new coupon
- if ( 'post-new.php' == $pagenow && 'tix_coupon' == $typenow )
- $submenu_file = 'edit.php?post_type=tix_coupon';
-
- // Make sure Attendees is selected when adding a new attendee
- if ( 'post-new.php' == $pagenow && 'tix_attendee' == $typenow )
- $submenu_file = 'edit.php?post_type=tix_attendee';
-
- // Make sure Tickets is selected when creating a new ticket
- if ( 'post-new.php' == $pagenow && 'tix_ticket' == $typenow )
- $submenu_file = 'edit.php?post_type=tix_ticket';
- }
-
- /**
- * The Tickets > Setup screen, uses the Settings API.
- */
- function menu_setup() {
- ?>
-
-
-
-
menu_setup_tabs(); ?>
-
-
- Tools? This tells
- * us which tab is currently active.
- */
- function get_setup_section() {
- if ( isset( $_REQUEST['tix_section'] ) )
- return strtolower( $_REQUEST['tix_section'] );
-
- return 'general';
- }
-
- /**
- * Tabs for Tickets > Tools, outputs the markup.
- */
- function menu_setup_tabs() {
- $current_section = $this->get_setup_section();
- $sections = array(
- 'general' => __( 'General', 'wordcamporg' ),
- 'payment' => __( 'Payment', 'wordcamporg' ),
- 'email-templates' => __( 'E-mail Templates', 'wordcamporg' ),
- );
-
- if ( $this->beta_features_enabled )
- $sections['beta'] = __( 'Beta', 'wordcamporg' );
-
- $sections = apply_filters( 'camptix_setup_sections', $sections );
-
- foreach ( $sections as $section_key => $section_caption ) {
- $active = $current_section === $section_key ? 'nav-tab-active' : '';
- $url = add_query_arg( 'tix_section', $section_key );
- echo '' . esc_html( $section_caption ) . '';
- }
- }
-
- /**
- * The Tickets > Tools screen, doesn't use the settings API, but does use tabs.
- */
- function menu_tools() {
- ?>
-
- Tools? This tells
- * us which tab is currently active.
- */
- function get_tools_section() {
- if ( isset( $_REQUEST['tix_section'] ) )
- return strtolower( $_REQUEST['tix_section'] );
-
- return 'summarize';
- }
-
- /**
- * Tabs for Tickets > Tools, outputs the markup.
- */
- function menu_tools_tabs() {
- $current_section = $this->get_tools_section();
- $sections = apply_filters( 'camptix_menu_tools_tabs', array(
- 'summarize' => __( 'Summarize', 'wordcamporg' ),
- 'revenue' => __( 'Revenue', 'wordcamporg' ),
- 'export' => __( 'Export', 'wordcamporg' ),
- 'notify' => __( 'Notify', 'wordcamporg' ),
- ) );
-
- if ( current_user_can( $this->caps['refund_all'] ) && ! $this->options['archived'] && $this->options['refund_all_enabled'] )
- $sections['refund'] = __( 'Refund', 'wordcamporg' );
-
- foreach ( $sections as $section_key => $section_caption ) {
- $active = $current_section === $section_key ? 'nav-tab-active' : '';
- $url = add_query_arg( 'tix_section', $section_key );
- echo '' . esc_html( $section_caption ) . '';
- }
- }
-
- /**
- * Tools > Summarize, the screen that outputs the summary tables,
- * provides an export option, powered by the summarize_admin_init method,
- * hooked (almost) at admin_init, because of additional headers. Doesn't use
- * the Settings API so check for nonces/referrers and caps.
- * @see summarize_admin_init()
- */
- function menu_tools_summarize() {
- $summarize_by = isset( $_POST['tix_summarize_by'] ) ? $_POST['tix_summarize_by'] : 'ticket';
- ?>
-
-
- get_available_summary_fields() ) ) : ?>
- get_available_summary_fields();
- $summary = $this->get_summary( $summarize_by );
- $summary_title = $fields[ $summarize_by ];
- $alt = '';
-
- $rows = array();
- foreach ( $summary as $entry )
- $rows[] = array(
- esc_html( $summary_title ) => esc_html( $entry['label'] ),
- __( 'Count', 'wordcamporg' ) => esc_html( $entry['count'] )
- );
-
- // Render the widefat table.
- $this->table( $rows, 'widefat tix-summarize' );
- ?>
-
-
- caps['manage_tools'] ) || 'summarize' != $this->get_tools_section() )
- return;
-
- if ( isset( $_POST['tix_export_summary'], $_POST['tix_summarize_by'] ) && check_admin_referer( 'tix_summarize' ) ) {
- $summarize_by = $_POST['tix_summarize_by'];
- if ( ! array_key_exists( $summarize_by, $this->get_available_summary_fields() ) )
- return;
-
- $fields = $this->get_available_summary_fields();
- $summary = $this->get_summary( $summarize_by );
- $summary_title = $fields[ $summarize_by ];
- $filename = sprintf( 'camptix-summary-%s-%s.csv', sanitize_title_with_dashes( $summary_title ), date( 'Y-m-d' ) );
-
- header( 'Content-Type: text/csv' );
- header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
- header( "Cache-control: private" );
- header( 'Pragma: private' );
- header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
-
- $stream = fopen( "php://output", 'w' );
-
- $headers = array( $summary_title, __( 'Count', 'wordcamporg' ) );
- fputcsv( $stream, self::esc_csv( $headers ) );
- foreach ( $summary as $entry ) {
- fputcsv( $stream, self::esc_csv( $entry ), ',', '"' );
- }
-
- fclose( $stream );
- die();
- }
- }
-
/**
* Returns a summary of all attendees. A lot of @magic here and
* watch out for actions and filters.
@@ -2765,7 +2347,7 @@ function menu_tools_export() {
function export_admin_init() {
global $post;
- if ( ! current_user_can( $this->caps['manage_tools'] ) || 'export' != $this->get_tools_section() )
+ if ( ! current_user_can( $this->caps['manage_tools'] ) || 'export' != Camptix_Admin::get_tools_section() )
return;
if ( isset( $_POST['tix_export_submit'], $_POST['tix_export_to'] ) && check_admin_referer( 'tix_export' ) ) {
@@ -3661,7 +3243,7 @@ function menu_tools_refund() {
* Runs before the page markup is printed so can add settings errors.
*/
function menu_tools_refund_admin_init() {
- if ( ! current_user_can( $this->caps['refund_all'] ) || 'refund' != $this->get_tools_section() )
+ if ( ! current_user_can( $this->caps['refund_all'] ) || 'refund' != Camptix_Admin::get_tools_section() )
return;
// Display results of completed refund-all job
@@ -8213,49 +7795,6 @@ function shutdown() {
$this->flush_tickets_page_seriously();
}
- /**
- * Helper function to create admin tables, give me a
- * $rows array and I'll do the rest.
- */
- function table( $rows, $classes='widefat' ) {
-
- if ( ! is_array( $rows ) || ! isset( $rows[0] ) )
- return;
-
- $alt = '';
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $value ) : ?>
-
-
-
-
-
-
-
-
- caps['manage_tools'], 'camptix_tools', array( $this, 'menu_tools' ) );
+ add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Setup', 'wordcamporg' ), __( 'Setup', 'wordcamporg' ), $this->caps['manage_options'], 'camptix_options', array( $this, 'menu_setup' ) );
+ add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Badges', 'wordcamporg' ), __( 'Badges', 'wordcamporg' ), $this->caps['manage_options'], 'camptix_badges', array( $this, 'menu_badges' ) );
+
+ remove_submenu_page( 'edit.php?post_type=tix_ticket', 'post-new.php?post_type=tix_ticket' );
+ }
+
+ /**
+ * When squeezing several custom post types under one top-level menu item, WordPress
+ * tends to get confused which menu item is currently active, especially around post-new.php.
+ * This function runs during admin_head and hacks into some of the global variables that are
+ * used to construct the menu.
+ */
+ function admin_menu_fix() {
+ global $self, $parent_file, $submenu_file, $plugin_page, $pagenow, $typenow;
+
+ // Make sure Coupons is selected when adding a new coupon
+ if ( 'post-new.php' == $pagenow && 'tix_coupon' == $typenow )
+ $submenu_file = 'edit.php?post_type=tix_coupon';
+
+ // Make sure Attendees is selected when adding a new attendee
+ if ( 'post-new.php' == $pagenow && 'tix_attendee' == $typenow )
+ $submenu_file = 'edit.php?post_type=tix_attendee';
+
+ // Make sure Tickets is selected when creating a new ticket
+ if ( 'post-new.php' == $pagenow && 'tix_ticket' == $typenow )
+ $submenu_file = 'edit.php?post_type=tix_ticket';
+ }
+
+ /**
+ * The Tickets > Setup screen, uses the Settings API.
+ */
+ function menu_setup() {
+ ?>
+
' . __( 'Beta features are things that are being worked on in CampTix, but are not quite finished yet. You can try them out, but we do not recommend doing that in a live environment on a real event. If you have any kind of feedback on any of the beta features, please let us know.', 'wordcamporg' ) . '
+
+
+ ' . __( 'General configuration.', 'wordcamporg' ) . '';
+ }
+}
+
+new Camptix_Admin;
\ No newline at end of file
From 807733d84dfdd785f4cda1ab66468937fe81d3f6 Mon Sep 17 00:00:00 2001
From: Paul Kevan
Date: Wed, 18 Dec 2024 12:13:16 +0000
Subject: [PATCH 02/15] phpcs
---
.../camptix/inc/class-camptix-admin.php | 86 +++++++++++--------
1 file changed, 51 insertions(+), 35 deletions(-)
diff --git a/public_html/wp-content/plugins/camptix/inc/class-camptix-admin.php b/public_html/wp-content/plugins/camptix/inc/class-camptix-admin.php
index 7c3287470e..ab38f12130 100644
--- a/public_html/wp-content/plugins/camptix/inc/class-camptix-admin.php
+++ b/public_html/wp-content/plugins/camptix/inc/class-camptix-admin.php
@@ -2,22 +2,28 @@
class Camptix_Admin extends CampTix_Plugin {
+ /**
+ * Fired as soon as this file is loaded, don't do anything
+ * but filters and actions here.
+ */
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
}
+ /**
+ * runs on init action.
+ */
public function init() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'admin_head', array( $this, 'admin_menu_fix' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
-
}
/**
* Oh the holy admin menu!
*/
- function admin_menu() {
+ public function admin_menu() {
add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Tools', 'wordcamporg' ), __( 'Tools', 'wordcamporg' ), $this->caps['manage_tools'], 'camptix_tools', array( $this, 'menu_tools' ) );
add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Setup', 'wordcamporg' ), __( 'Setup', 'wordcamporg' ), $this->caps['manage_options'], 'camptix_options', array( $this, 'menu_setup' ) );
add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Badges', 'wordcamporg' ), __( 'Badges', 'wordcamporg' ), $this->caps['manage_options'], 'camptix_badges', array( $this, 'menu_badges' ) );
@@ -31,26 +37,29 @@ function admin_menu() {
* This function runs during admin_head and hacks into some of the global variables that are
* used to construct the menu.
*/
- function admin_menu_fix() {
+ public function admin_menu_fix() {
global $self, $parent_file, $submenu_file, $plugin_page, $pagenow, $typenow;
- // Make sure Coupons is selected when adding a new coupon
- if ( 'post-new.php' == $pagenow && 'tix_coupon' == $typenow )
+ // Make sure Coupons is selected when adding a new coupon.
+ if ( 'post-new.php' == $pagenow && 'tix_coupon' == $typenow ) {
$submenu_file = 'edit.php?post_type=tix_coupon';
+ }
- // Make sure Attendees is selected when adding a new attendee
- if ( 'post-new.php' == $pagenow && 'tix_attendee' == $typenow )
+ // Make sure Attendees is selected when adding a new attendee.
+ if ( 'post-new.php' == $pagenow && 'tix_attendee' == $typenow ) {
$submenu_file = 'edit.php?post_type=tix_attendee';
+ }
- // Make sure Tickets is selected when creating a new ticket
- if ( 'post-new.php' == $pagenow && 'tix_ticket' == $typenow )
+ // Make sure Tickets is selected when creating a new ticket.
+ if ( 'post-new.php' == $pagenow && 'tix_ticket' == $typenow ) {
$submenu_file = 'edit.php?post_type=tix_ticket';
+ }
}
/**
* The Tickets > Setup screen, uses the Settings API.
*/
- function menu_setup() {
+ public function menu_setup() {
?>
@@ -73,7 +82,7 @@ function menu_setup() {
/**
* Tabs for Tickets > Tools, outputs the markup.
*/
- function menu_setup_tabs() {
+ public function menu_setup_tabs() {
$current_section = $this->get_setup_section();
$sections = array(
'general' => __( 'General', 'wordcamporg' ),
@@ -81,8 +90,9 @@ function menu_setup_tabs() {
'email-templates' => __( 'E-mail Templates', 'wordcamporg' ),
);
- if ( $this->beta_features_enabled )
+ if ( $this->beta_features_enabled ) {
$sections['beta'] = __( 'Beta', 'wordcamporg' );
+ }
$sections = apply_filters( 'camptix_setup_sections', $sections );
@@ -96,7 +106,7 @@ function menu_setup_tabs() {
/**
* The Tickets > Tools screen, doesn't use the settings API, but does use tabs.
*/
- function menu_tools() {
+ public function menu_tools() {
?>
@@ -125,9 +135,10 @@ function menu_tools() {
* Remember the tabs in Tickets > Tools? This tells
* us which tab is currently active.
*/
- function get_setup_section() {
- if ( isset( $_REQUEST['tix_section'] ) )
+ public function get_setup_section() {
+ if ( isset( $_REQUEST['tix_section'] ) ) {
return strtolower( $_REQUEST['tix_section'] );
+ }
return 'general';
}
@@ -136,9 +147,10 @@ function get_setup_section() {
* Remember the tabs in Tickets > Tools? This tells
* us which tab is currently active.
*/
- function get_tools_section() {
- if ( isset( $_REQUEST['tix_section'] ) )
+ public function get_tools_section() {
+ if ( isset( $_REQUEST['tix_section'] ) ) {
return strtolower( $_REQUEST['tix_section'] );
+ }
return 'summarize';
}
@@ -146,7 +158,7 @@ function get_tools_section() {
/**
* Tabs for Tickets > Tools, outputs the markup.
*/
- function menu_tools_tabs() {
+ public function menu_tools_tabs() {
$current_section = $this->get_tools_section();
$sections = apply_filters( 'camptix_menu_tools_tabs', array(
'summarize' => __( 'Summarize', 'wordcamporg' ),
@@ -155,8 +167,9 @@ function menu_tools_tabs() {
'notify' => __( 'Notify', 'wordcamporg' ),
) );
- if ( current_user_can( $this->caps['refund_all'] ) && ! $this->options['archived'] && $this->options['refund_all_enabled'] )
+ if ( current_user_can( $this->caps['refund_all'] ) && ! $this->options['archived'] && $this->options['refund_all_enabled'] ) {
$sections['refund'] = __( 'Refund', 'wordcamporg' );
+ }
foreach ( $sections as $section_key => $section_caption ) {
$active = $current_section === $section_key ? 'nav-tab-active' : '';
@@ -172,7 +185,7 @@ function menu_tools_tabs() {
* the Settings API so check for nonces/referrers and caps.
* @see summarize_admin_init()
*/
- function menu_tools_summarize() {
+ public function menu_tools_summarize() {
$summarize_by = isset( $_POST['tix_summarize_by'] ) ? $_POST['tix_summarize_by'] : 'ticket';
?>
beta_features_enabled ) {
break;
}
-
+
add_settings_section( 'general', __( 'Beta Features', 'wordcamporg' ), array( $this, 'menu_setup_section_beta' ), 'camptix_options' );
$this->add_settings_field_helper( 'reservations_enabled', __( 'Enable Reservations', 'wordcamporg' ), 'field_yesno', false,
From 5c4639a28f25862672b707c55b79fd1e553cf178 Mon Sep 17 00:00:00 2001
From: Paul Kevan
Date: Wed, 18 Dec 2024 14:11:13 +0000
Subject: [PATCH 04/15] more phpcs
---
.../camptix/inc/class-camptix-admin.php | 90 ++++++++++++-------
1 file changed, 60 insertions(+), 30 deletions(-)
diff --git a/public_html/wp-content/plugins/camptix/inc/class-camptix-admin.php b/public_html/wp-content/plugins/camptix/inc/class-camptix-admin.php
index 122391af6a..11522e2f6d 100644
--- a/public_html/wp-content/plugins/camptix/inc/class-camptix-admin.php
+++ b/public_html/wp-content/plugins/camptix/inc/class-camptix-admin.php
@@ -169,7 +169,7 @@ public function menu_tools_tabs() {
) );
if ( current_user_can( $this->caps['refund_all'] ) && ! $this->options['archived'] && $this->options['refund_all_enabled'] ) {
- $sections['refund'] = __( 'Refund', 'wordcamporg' );
+ $sections['refund'] = esc_html__( 'Refund', 'wordcamporg' );
}
foreach ( $sections as $section_key => $section_caption ) {
@@ -229,7 +229,7 @@ public function menu_tools_summarize() {
foreach ( $summary as $entry ) {
$rows[] = array(
esc_html( $summary_title ) => esc_html( $entry['label'] ),
- __( 'Count', 'wordcamporg' ) => esc_html( $entry['count'] )
+ esc_html__( 'Count', 'wordcamporg' ) => esc_html( $entry['count'] )
);
}
// Render the widefat table.
@@ -323,15 +323,18 @@ public function table( $rows, $classes='widefat' ) {
query_vars ) { // only on singular admin pages
+ if ( ! $wp_query->query_vars ) { // only on singular admin pages.
if ( 'tix_ticket' == get_post_type() || 'tix_coupon' == get_post_type() ) {
}
}
- // Let's see whether to include admin.css and admin.js
+ // Let's see whether to include admin.css and admin.js.
if ( is_admin() ) {
$screen = get_current_screen();
$post_types = array( 'tix_ticket', 'tix_coupon', 'tix_email', 'tix_attendee' );
@@ -382,13 +385,16 @@ public function admin_enqueue_scripts() {
public function admin_init() {
register_setting( 'camptix_options', 'camptix_options', array( $this, 'validate_options' ) );
- // Add settings fields
+ // Add settings fields.
$this->menu_setup_controls();
// Let's add some help tabs.
require_once dirname( __FILE__ ) . '/help.php';
}
+ /**
+ * Menu Setup general section.
+ */
public function menu_setup_controls() {
wp_enqueue_script( 'jquery-ui' );
$section = $this->get_setup_section();
@@ -402,7 +408,7 @@ public function menu_setup_controls() {
$this->add_settings_field_helper( 'currency', __( 'Currency', 'wordcamporg' ), 'field_currency' );
$this->add_settings_field_helper( 'refunds_enabled', __( 'Enable Refunds', 'wordcamporg' ), 'field_enable_refunds', false,
- __( "This will allows your customers to refund their tickets purchase by filling out a simple refund form.", 'wordcamporg' )
+ esc_html__( "This will allows your customers to refund their tickets purchase by filling out a simple refund form.", 'wordcamporg' )
);
break;
@@ -411,51 +417,66 @@ public function menu_setup_controls() {
$payment_method_obj = $this->get_payment_method_by_id( $key );
add_settings_section( 'payment_' . $key, $payment_method_obj->name, array( $payment_method_obj, '_camptix_settings_section_callback' ), 'camptix_options' );
- add_settings_field( 'payment_method_' . $key . '_enabled', __( 'Enabled', 'wordcamporg' ), array( $payment_method_obj, '_camptix_settings_enabled_callback' ), 'camptix_options', 'payment_' . $key, array(
- 'name' => "camptix_options[payment_methods][{$key}]",
- 'value' => isset( $this->options['payment_methods'][$key] ) ? (bool) $this->options['payment_methods'][ $key ] : false,
- ) );
+ add_settings_field(
+ 'payment_method_' . $key . '_enabled',
+ __( 'Enabled', 'wordcamporg' ),
+ array( $payment_method_obj, '_camptix_settings_enabled_callback' ),
+ 'camptix_options', 'payment_' . $key, array(
+ 'name' => "camptix_options[payment_methods][{$key}]",
+ 'value' => isset( $this->options[ 'payment_methods' ][$key] ) ? (bool) $this->options[ 'payment_methods' ][ $key ] : false,
+ )
+ );
$payment_method_obj->payment_settings_fields();
}
break;
case 'email-templates':
add_settings_section( 'general', __( 'E-mail Templates', 'wordcamporg' ), array( $this, 'menu_setup_section_email_templates' ), 'camptix_options' );
- $this->add_settings_field_helper( 'email_template_single_purchase', __( 'Single purchase', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_multiple_purchase', __( 'Multiple purchase', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_multiple_purchase_receipt', __( 'Multiple purchase (receipt)', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_pending_succeeded', __( 'Pending Payment Succeeded', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_pending_failed', __( 'Pending Payment Failed', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_single_refund', __( 'Single Refund', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_multiple_refund', __( 'Multiple Refund', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_single_purchase', esc_html__( 'Single purchase', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_multiple_purchase', esc_html__( 'Multiple purchase', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_multiple_purchase_receipt', esc_html__( 'Multiple purchase (receipt)', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_pending_succeeded', esc_html__( 'Pending Payment Succeeded', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_pending_failed', esc_html__( 'Pending Payment Failed', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_single_refund', esc_html__( 'Single Refund', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_multiple_refund', esc_html__( 'Multiple Refund', 'wordcamporg' ), 'field_textarea' );
foreach ( apply_filters( 'camptix_custom_email_templates', array() ) as $key => $template ) {
$this->add_settings_field_helper( $key, $template['title'], $template['callback_method'] );
}
- // Add a reset templates button
+ // Add a reset templates button.
add_action( 'camptix_setup_buttons', array( $this, 'setup_buttons_reset_templates' ) );
break;
case 'beta':
-
if ( ! $this->beta_features_enabled ) {
break;
}
- add_settings_section( 'general', __( 'Beta Features', 'wordcamporg' ), array( $this, 'menu_setup_section_beta' ), 'camptix_options' );
+ add_settings_section( 'general', esc_html__( 'Beta Features', 'wordcamporg' ), array( $this, 'menu_setup_section_beta' ), 'camptix_options' );
- $this->add_settings_field_helper( 'reservations_enabled', __( 'Enable Reservations', 'wordcamporg' ), 'field_yesno', false,
- __( "Reservations is a way to make sure that a certain group of people, can always purchase their tickets, even if you sell out fast.", 'wordcamporg' )
+ $this->add_settings_field_helper(
+ 'reservations_enabled',
+ esc_html__( 'Enable Reservations', 'wordcamporg' ),
+ 'field_yesno',
+ false,
+ esc_html__( 'Reservations is a way to make sure that a certain group of people, can always purchase their tickets, even if you sell out fast.', 'wordcamporg' )
);
if ( current_user_can( $this->caps['refund_all'] ) ) {
- $this->add_settings_field_helper( 'refund_all_enabled', __( 'Enable Refund All', 'wordcamporg' ), 'field_yesno', false,
- __( "Allows to refund all purchased tickets by an admin via the Tools menu.", 'wordcamporg' )
+ $this->add_settings_field_helper(
+ 'refund_all_enabled',
+ esc_html__( 'Enable Refund All', 'wordcamporg' ),
+ 'field_yesno', false,
+ esc_html__( 'Allows to refund all purchased tickets by an admin via the Tools menu.', 'wordcamporg' )
);
}
- $this->add_settings_field_helper( 'archived', __( 'Archived Event', 'wordcamporg' ), 'field_yesno', false,
- __( "Archived events are read-only.", 'wordcamporg' )
+ $this->add_settings_field_helper(
+ 'archived',
+ esc_html__( 'Archived Event', 'wordcamporg' ),
+ 'field_yesno',
+ false,
+ esc_html__( 'Archived events are read-only.', 'wordcamporg' )
);
break;
default:
@@ -464,17 +485,23 @@ public function menu_setup_controls() {
}
}
+ /**
+ * Menu Setup Beta section.
+ */
public function menu_setup_section_beta() {
- echo '
' . __( 'Beta features are things that are being worked on in CampTix, but are not quite finished yet. You can try them out, but we do not recommend doing that in a live environment on a real event. If you have any kind of feedback on any of the beta features, please let us know.', 'wordcamporg' ) . '
';
+ echo '
' . esc_html__( 'Beta features are things that are being worked on in CampTix, but are not quite finished yet. You can try them out, but we do not recommend doing that in a live environment on a real event. If you have any kind of feedback on any of the beta features, please let us know.', 'wordcamporg' ) . '
';
}
+ /**
+ * Menu Setup Email template section.
+ */
public function menu_setup_section_email_templates() {
?>
-
+
@@ -489,9 +516,12 @@ public function menu_setup_section_email_templates() {
' . __( 'General configuration.', 'wordcamporg' ) . '';
+ echo '