PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 2.13
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v2.13
5.6.0 5.5.0 5.4.0 5.3.2 5.3.1 5.1.6 5.1.5 trunk 2.1.5 2.11 2.12 2.13 2.15 3.0.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.51 3.0.60 3.0.61 3.0.62 3.0.70 3.0.71 3.0.72 All 35 releases
double-opt-in / core / CategoryOptions.class.php

CategoryOptions.class.php in Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification 2.13, at core/CategoryOptions.class.php

118 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace forge12\contactform7\CF7DoubleOptIn {
4 if (!defined('ABSPATH')) {
5 exit;
6 }
7
8 /**
9 * Class UICategories
10 *
11 * @package forge12\contactform7\CF7DoubleOptIn
12 */
13 class CategoryOptions
14 {
15 private static $_instance = null;
16
17 public static function getInstance()
18 {
19 if (null === self::$_instance) {
20 self::$_instance = new CategoryOptions();
21 }
22 return self::$_instance;
23 }
24
25 private function __construct()
26 {
27 // Add additional actions
28 add_action('f12_cf7_doubleoptin_ui_table_options', array($this, 'addOption'));
29
30 add_action('admin_init', array($this, 'init'));
31 }
32
33 /**
34 * After initializing the WordPress Admi
35 *
36 * @return void
37 */
38 public function init()
39 {
40 if (isset($_POST['update-category'])) {
41 $this->update_categories();
42 }
43 }
44
45 /**
46 * Assign the new categories to the selected opt ins.
47 *
48 * @return void
49 */
50 private function update_categories()
51 {
52 if (!\wp_verify_nonce($_POST['f12_cf7_doubleoptin_ui_table_options_nonce'], 'f12_cf7_doubleoptin_ui_table_options_action')) {
53 return;
54 }
55
56 if (!isset($_POST['optin-id']) || !is_array($_POST['optin-id'])) {
57 return;
58 }
59
60 if (!isset($_POST['category'])) {
61 return;
62 }
63 $category_id = (int)$_POST['category'];
64
65 $Category = Category::get_by_id($category_id);
66
67 if (null == $Category && 0 !== $category_id) {
68 return;
69 }
70
71 $optinIds = array_map('intval', $_POST['optin-id']);
72
73 foreach ($optinIds as $id) {
74 OptIn::update_category_by_id($id, $category_id);
75 }
76 }
77
78 /**
79 * Return an Select Field for Categories
80 *
81 * @return string
82 */
83 public function select_category($selected = 0)
84 {
85 $atts = array(
86 'perPage' => -1,
87 'orderBy' => 'name',
88 'order' => 'ASC'
89 );
90
91 $list = Category::get_list($atts, $numberOfPages);
92
93 $response = '<option value="0">' . __('Please select', 'double-opt-in') . '</option>';
94 foreach ($list as $Category/** @var Category $Category */) {
95 $selected_html = $selected == $Category->get_id() ? 'selected="selected"' : '';
96 $response .= '<option value="' . esc_attr($Category->get_id()) . '" '.$selected_html.'>' . esc_attr($Category->get_name()) . '</option>';
97 }
98 return '<select name="category">' . $response . '</select>';
99 }
100
101 /**
102 * Add a Option to update the given Categories
103 *
104 * @return string
105 */
106 public function addOption()
107 {
108 ?>
109 <li>
110 <?php _e('Change Category to: '); ?>
111 <?php echo wp_kses($this->select_category(), array('select' => array('name' => array()), 'option' => array('value' => array(), 'selected' => array()))); ?>
112 <input type="submit" class="button" name="update-category"
113 value="<?php _e('Update', 'double-opt-in'); ?>"/>
114 </li>
115 <?php
116 }
117 }
118 }