charitable
/
includes
/
admin
/
campaign-builder
/
panels
/
settings
/
class-settings-campaign-creator.php
class-settings-campaign-creator.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.11, at includes/admin/campaign-builder/panels/settings/class-settings-campaign-creator.php
| 1 | <?php |
| 2 | /** |
| 3 | * The class that defines a subpanel for the settings area for the campaign builder. |
| 4 | * |
| 5 | * @package Charitable/Admin/Charitable_Campaign_Meta_Boxes |
| 6 | * @author David Bisset |
| 7 | * @copyright Copyright (c) 2023, WP Charitable LLC |
| 8 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | * @since 1.8.0 |
| 10 | * @version. 1.8.9.1 |
| 11 | */ |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | if ( ! class_exists( 'Charitable_Builder_Panel_Settings_Campaign_Creator' ) ) : |
| 18 | |
| 19 | /** |
| 20 | * General subpanel for Settings Panel for campaign builder. |
| 21 | * |
| 22 | * @since 1.8.0 |
| 23 | */ |
| 24 | class Charitable_Builder_Panel_Settings_Campaign_Creator { |
| 25 | |
| 26 | /** |
| 27 | * Slug. |
| 28 | * |
| 29 | * @since 1.8.0 |
| 30 | * |
| 31 | * @var string |
| 32 | */ |
| 33 | private $slug = 'campaign-creator'; |
| 34 | |
| 35 | /** |
| 36 | * The label/headline at the top of the panel. |
| 37 | * |
| 38 | * @since 1.8.0 |
| 39 | * |
| 40 | * @var string |
| 41 | */ |
| 42 | private $primary_label = ''; |
| 43 | |
| 44 | /** |
| 45 | * Determines if the tab is initially active on a fresh new page load. |
| 46 | * |
| 47 | * @since 1.8.0 |
| 48 | * |
| 49 | * @var string |
| 50 | */ |
| 51 | private $active = false; |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * Get things going. Add action hooks for the sidebar menu and the panel itself. |
| 56 | * |
| 57 | * @since 1.8.0 |
| 58 | */ |
| 59 | public function __construct() { |
| 60 | |
| 61 | $this->primary_label = esc_html__( 'Campaign Creator', 'charitable' ); |
| 62 | |
| 63 | add_action( 'charitable_campaign_builder_settings_sidebar', array( $this, 'sidebar_tab' ) ); |
| 64 | add_action( 'charitable_campaign_builder_settings_panels', array( $this, 'panel_content' ) ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Generate sidebar html. |
| 69 | * |
| 70 | * @since 1.8.0 |
| 71 | */ |
| 72 | public function sidebar_tab() { |
| 73 | |
| 74 | $active = ( true === apply_filters( 'charitable_campaign_builder_settings_sidebar_active', $this->active, $this->slug ) ) ? 'active' : false; |
| 75 | |
| 76 | echo '<a href="#" class="charitable-panel-sidebar-section charitable-panel-sidebar-section-' . $this->slug . ' ' . $active . '" data-section="' . $this->slug . '">' . $this->primary_label . ' <i class="fa fa-angle-right charitable-toggle-arrow"></i></a>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Generate panel content. |
| 81 | * |
| 82 | * @since 1.8.0 |
| 83 | * @version 1.8.9.1 |
| 84 | */ |
| 85 | public function panel_content( $campaign_data = false, $campaign_id = false ) { |
| 86 | |
| 87 | $charitable_builder_form_fields = new Charitable_Builder_Form_Fields(); |
| 88 | $settings = new Charitable_Builder_Panel_Settings(); |
| 89 | |
| 90 | $campaign_id = ( ( false === $campaign_id && empty( $campaign_data['id'] ) ) && isset( $_GET['campaign_id'] ) ) ? intval( $_GET['campaign_id'] ) : intval( $campaign_id ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 91 | $campaign_id = ( 0 === $campaign_id && ! empty( $campaign_data['id'] ) ) ? intval( $campaign_data['id'] ) : $campaign_id; |
| 92 | |
| 93 | $active = ( true === apply_filters( 'charitable_campaign_builder_settings_sidebar_active', $this->active, $this->slug ) ) ? 'active' : false; |
| 94 | $style = ( true === apply_filters( 'charitable_campaign_builder_settings_sidebar_active', $this->active, $this->slug ) ) ? 'display: block;' : false; |
| 95 | |
| 96 | ob_start(); |
| 97 | |
| 98 | ?> |
| 99 | |
| 100 | <div class="charitable-panel-content-section charitable-panel-content-section-<?php echo esc_attr( $this->slug ); ?> <?php echo esc_attr( $active ); ?>" style="<?php echo esc_attr( $style ); ?>"> |
| 101 | <div class="charitable-panel-content-section-title"><?php echo esc_html( $this->primary_label ); ?></div> |
| 102 | |
| 103 | <?php |
| 104 | |
| 105 | // get all users. |
| 106 | $users = get_users(); |
| 107 | $campaign = isset( $campaign_id ) && 0 !== $campaign_id ? get_post( $campaign_id ) : false; |
| 108 | |
| 109 | if ( ! empty( $users ) ) { |
| 110 | |
| 111 | $users_to_pass = array(); |
| 112 | |
| 113 | foreach ( $users as $user ) { |
| 114 | $users_to_pass[ $user->data->ID ] = $user->data->user_login; |
| 115 | } |
| 116 | |
| 117 | $campaign_creator_id = ( false === $campaign ) ? get_current_user_id() : $campaign->post_author; |
| 118 | |
| 119 | echo $charitable_builder_form_fields->generate_campaign_creator_info( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 120 | $settings->campaign_data_settings( 'campaign_creator_id', 'campaign-creator' ), |
| 121 | '', |
| 122 | array( |
| 123 | 'id' => 'campaign_campaign_creator_info', |
| 124 | 'creator_id' => intval( $campaign_creator_id ), |
| 125 | ) |
| 126 | ); |
| 127 | |
| 128 | echo $charitable_builder_form_fields->generate_dropdown( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 129 | $settings->campaign_data_settings( 'campaign_creator_id', 'campaign-creator' ), |
| 130 | esc_html__( 'Change the campaign creator', 'charitable' ), |
| 131 | array( |
| 132 | 'id' => 'campaign_campaign_creator_id', |
| 133 | 'name' => array( 'settings', esc_attr( $this->slug ), 'campaign_creator_id' ), |
| 134 | 'class' => 'campaign-builder-campaign-creator-id', |
| 135 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 136 | 'options' => $users_to_pass, |
| 137 | 'html' => true, |
| 138 | 'selected_value' => intval( $campaign_creator_id ), |
| 139 | ) |
| 140 | ); |
| 141 | |
| 142 | } |
| 143 | |
| 144 | ?> |
| 145 | </div> |
| 146 | |
| 147 | <?php |
| 148 | |
| 149 | $html = ob_get_clean(); |
| 150 | |
| 151 | echo wp_kses_post( $html ); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | new Charitable_Builder_Panel_Settings_Campaign_Creator(); |
| 156 | |
| 157 | endif; |
| 158 |