| 1 |
<?php |
| 2 |
|
| 3 |
namespace UiCoreElements; |
| 4 |
|
| 5 |
/** |
| 6 |
* Admin Pages Handler |
| 7 |
*/ |
| 8 |
class Admin |
| 9 |
{ |
| 10 |
/** |
| 11 |
* Constructor function to initialize hooks |
| 12 |
* |
| 13 |
* @return void |
| 14 |
* @author Andrei Voica <andrei@uicore.co> |
| 15 |
* @since 1.0.0 |
| 16 |
*/ |
| 17 |
public function __construct() |
| 18 |
{ |
| 19 |
$this->elementor_style(); |
| 20 |
|
| 21 |
add_action('admin_menu', [$this, 'admin_menu']); |
| 22 |
add_action('admin_init', [$this, 'init_hooks']); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Add admin menu page |
| 27 |
* |
| 28 |
* @return void |
| 29 |
* @author Andrei Voica <andrei@uicore.co> |
| 30 |
* @since 1.0.5 |
| 31 |
*/ |
| 32 |
public function admin_menu() |
| 33 |
{ |
| 34 |
// Settings page (only required if uicore framework is not active) |
| 35 |
// if (!\class_exists('\UiCore\Helper')) { |
| 36 |
$hook = add_submenu_page( |
| 37 |
'options-general.php', |
| 38 |
'UiCore Elements', |
| 39 |
'UiCore Elements', |
| 40 |
'manage_options', |
| 41 |
'uicore-elements', |
| 42 |
[$this, 'plugin_page'] |
| 43 |
); |
| 44 |
|
| 45 |
// } |
| 46 |
|
| 47 |
// Connect handle |
| 48 |
add_submenu_page( |
| 49 |
null, |
| 50 |
'UiCore Connect', |
| 51 |
'UiCore Connect', |
| 52 |
'manage_options', |
| 53 |
'uicore_connect_free', |
| 54 |
[$this, 'connect_page_callback'] |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Initialize hooks for settings fields and sections |
| 60 |
* |
| 61 |
* @return void |
| 62 |
* @author Andrei Voica <andrei@uicore.co> |
| 63 |
* @since 1.0.5 |
| 64 |
*/ |
| 65 |
public function init_hooks() |
| 66 |
{ |
| 67 |
register_setting('uicore_elements_recaptcha', 'uicore_elements_recaptcha_site_key', ['sanitize_callback' => 'sanitize_text_field']); |
| 68 |
register_setting('uicore_elements_recaptcha', 'uicore_elements_recaptcha_secret_key', ['sanitize_callback' => 'sanitize_text_field']); |
| 69 |
|
| 70 |
add_settings_section('uicore_elements_recaptcha_section', 'reCAPTCHA Keys', [$this, 'recaptcha_section'], 'uicore_elements_recaptcha'); |
| 71 |
|
| 72 |
add_settings_field('uicore_elements_recaptcha_site_key', 'Site Key', [$this, 'site_key'], 'uicore_elements_recaptcha', 'uicore_elements_recaptcha_section'); |
| 73 |
add_settings_field('uicore_elements_recaptcha_secret_key', 'Secret Key', [$this, 'secret_key'], 'uicore_elements_recaptcha', 'uicore_elements_recaptcha_section'); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Render plugin page |
| 78 |
* |
| 79 |
* @return void |
| 80 |
* @author Andrei Voica <andrei@uicore.co> |
| 81 |
* @since 1.0.5 |
| 82 |
*/ |
| 83 |
public function plugin_page() |
| 84 |
{ |
| 85 |
// check user capabilities |
| 86 |
if (!current_user_can('manage_options')) { |
| 87 |
return; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
// show error/update messages |
| 92 |
settings_errors('uicoreelements_messages'); |
| 93 |
|
| 94 |
// display plugin page |
| 95 |
?> |
| 96 |
<div class="wrap"> |
| 97 |
<h1>UiCore Elements Settings</h1> |
| 98 |
|
| 99 |
|
| 100 |
<form method="post" action="options.php" style="margin-top:40px"> |
| 101 |
<?php |
| 102 |
settings_fields('uicore_elements_recaptcha'); |
| 103 |
do_settings_sections('uicore_elements_recaptcha'); |
| 104 |
submit_button(); |
| 105 |
?> |
| 106 |
</form> |
| 107 |
|
| 108 |
</div> |
| 109 |
<?php |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Render reCAPTCHA section description |
| 114 |
* |
| 115 |
* @return void |
| 116 |
* @author Andrei Voica <andrei@uicore.co> |
| 117 |
* @since 1.0.5 |
| 118 |
*/ |
| 119 |
public function recaptcha_section() |
| 120 |
{ |
| 121 |
echo '<p class="description">Go to your Google <a href="https://www.google.com/recaptcha/admin/create" target="_blank">reCAPTCHA</a>, choose between V2 or V3 versions and create your API keys</p>'; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Render Site Key field |
| 126 |
* |
| 127 |
* @return void |
| 128 |
* @author Andrei Voica <andrei@uicore.co> |
| 129 |
* @since 1.0.5 |
| 130 |
*/ |
| 131 |
public function site_key() |
| 132 |
{ |
| 133 |
$site_key = get_option('uicore_elements_recaptcha_site_key'); |
| 134 |
echo '<input type="text" name="uicore_elements_recaptcha_site_key" value="' . esc_attr($site_key) . '" class="regular-text" />'; |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Render Secret Key field |
| 139 |
* |
| 140 |
* @return void |
| 141 |
* @author Andrei Voica <andrei@uicore.co> |
| 142 |
* @since 1.0.5 |
| 143 |
*/ |
| 144 |
public function secret_key() |
| 145 |
{ |
| 146 |
$secret_key = get_option('uicore_elements_recaptcha_secret_key'); |
| 147 |
echo '<input type="text" name="uicore_elements_recaptcha_secret_key" value="' . esc_attr($secret_key) . '" class="regular-text" />'; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
/** |
| 152 |
* Elementor Editor Style, Fonts and Scripts |
| 153 |
* |
| 154 |
* @return void |
| 155 |
* @author Andrei Voica <andrei@uicore.co |
| 156 |
* @since 1.0.0 |
| 157 |
*/ |
| 158 |
public function elementor_style() |
| 159 |
{ |
| 160 |
add_action('elementor/editor/before_enqueue_scripts', function () { |
| 161 |
|
| 162 |
echo '<style id="uicore-csss" > |
| 163 |
.elementor-element .icon .ui-e-widget:after { |
| 164 |
height: 28px; |
| 165 |
width: 28px; |
| 166 |
margin-right: 10px; |
| 167 |
border-radius: 3px; |
| 168 |
background-color: #532df5; |
| 169 |
background-image: url("data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' width=\'16\' height=\'16\' viewBox=\'0 0 16 16\' xml:space=\'preserve\'%3E%3Cpath d=\'M5.383 15.217c3.1 0 5.4-2.3 5.4-5.3v-7.9h-2.9v7.9c0 1.4-1.1 2.5-2.5 2.5s-2.5-1.1-2.5-2.5v-7.9h-2.9v7.9c0 3 2.3 5.3 5.4 5.3zM14.283 4.117c1 0 1.7-.7 1.7-1.7s-.7-1.7-1.7-1.7-1.7.7-1.7 1.7.7 1.7 1.7 1.7zM15.683 15.017v-9.6h-2.8v9.6z\' fill=\'%23fff\'/%3E%3C/svg%3E"); |
| 170 |
background-size: 16px; |
| 171 |
background-position: center; |
| 172 |
background-repeat: no-repeat; |
| 173 |
} |
| 174 |
|
| 175 |
.elementor-element .icon .ui-e-widget:after { |
| 176 |
content: ""; |
| 177 |
position: absolute; |
| 178 |
right: 5px; |
| 179 |
top: 5px; |
| 180 |
margin-right: 0; |
| 181 |
width: 16px; |
| 182 |
height: 16px; |
| 183 |
background-size: 9px; |
| 184 |
background-color: #656c7196; |
| 185 |
transition: background-color .3s ease-in-out; |
| 186 |
} |
| 187 |
.elementor-element:hover .icon .ui-e-widget:after { |
| 188 |
background-color: #532df5; |
| 189 |
transition: background-color .3s ease-in-out; |
| 190 |
} |
| 191 |
</style>'; |
| 192 |
}); |
| 193 |
} |
| 194 |
} |
| 195 |
|