| 1 |
<?php |
| 2 |
/** |
| 3 |
* ConvertKit general plugin functions. |
| 4 |
* |
| 5 |
* @package ConvertKit |
| 6 |
* @author ConvertKit |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Runs the activation and update routines when the plugin is activated. |
| 11 |
* |
| 12 |
* @since 1.9.7.4 |
| 13 |
* |
| 14 |
* @param bool $network_wide Is network wide activation. |
| 15 |
*/ |
| 16 |
function convertkit_plugin_activate( $network_wide ) { |
| 17 |
|
| 18 |
// Initialise Plugin. |
| 19 |
$convertkit = WP_ConvertKit(); |
| 20 |
$convertkit->initialize(); |
| 21 |
|
| 22 |
// Check if we are on a multisite install, activating network wide, or a single install. |
| 23 |
if ( ! is_multisite() || ! $network_wide ) { |
| 24 |
// Single Site activation. |
| 25 |
$convertkit->get_class( 'setup' )->activate(); |
| 26 |
|
| 27 |
// Set a transient for 30 seconds to redirect to the setup screen on activation. |
| 28 |
set_transient( 'convertkit-setup', true, 30 ); |
| 29 |
} else { |
| 30 |
// Multisite network wide activation. |
| 31 |
$sites = get_sites( |
| 32 |
array( |
| 33 |
'number' => 0, |
| 34 |
) |
| 35 |
); |
| 36 |
foreach ( $sites as $site ) { |
| 37 |
switch_to_blog( (int) $site->blog_id ); |
| 38 |
$convertkit->get_class( 'setup' )->activate(); |
| 39 |
restore_current_blog(); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Runs the activation and update routines when the plugin is activated |
| 47 |
* on a WordPress multisite setup. |
| 48 |
* |
| 49 |
* @since 1.9.7.4 |
| 50 |
* |
| 51 |
* @param WP_Site|int $site_or_blog_id WP_Site or Blog ID. |
| 52 |
*/ |
| 53 |
function convertkit_plugin_activate_new_site( $site_or_blog_id ) { |
| 54 |
|
| 55 |
// Check if $site_or_blog_id is a WP_Site or a blog ID. |
| 56 |
if ( is_a( $site_or_blog_id, 'WP_Site' ) ) { |
| 57 |
$site_or_blog_id = $site_or_blog_id->blog_id; |
| 58 |
} |
| 59 |
|
| 60 |
// Initialise Plugin. |
| 61 |
$convertkit = WP_ConvertKit(); |
| 62 |
$convertkit->initialize(); |
| 63 |
|
| 64 |
// Run installation routine. |
| 65 |
switch_to_blog( $site_or_blog_id ); |
| 66 |
$convertkit->get_class( 'setup' )->activate(); |
| 67 |
restore_current_blog(); |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Runs the deactivation routine when the plugin is deactivated. |
| 73 |
* |
| 74 |
* @since 1.9.7.4 |
| 75 |
* |
| 76 |
* @param bool $network_wide Is network wide deactivation. |
| 77 |
*/ |
| 78 |
function convertkit_plugin_deactivate( $network_wide ) { |
| 79 |
|
| 80 |
// Initialise Plugin. |
| 81 |
$convertkit = WP_ConvertKit(); |
| 82 |
$convertkit->initialize(); |
| 83 |
|
| 84 |
// Check if we are on a multisite install, activating network wide, or a single install. |
| 85 |
if ( ! is_multisite() || ! $network_wide ) { |
| 86 |
// Single Site activation. |
| 87 |
$convertkit->get_class( 'setup' )->deactivate(); |
| 88 |
} else { |
| 89 |
// Multisite network wide activation. |
| 90 |
$sites = get_sites( |
| 91 |
array( |
| 92 |
'number' => 0, |
| 93 |
) |
| 94 |
); |
| 95 |
foreach ( $sites as $site ) { |
| 96 |
switch_to_blog( (int) $site->blog_id ); |
| 97 |
$convertkit->get_class( 'setup' )->deactivate(); |
| 98 |
restore_current_blog(); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Helper method to get supported Post Types. |
| 106 |
* |
| 107 |
* @since 1.9.6 |
| 108 |
* |
| 109 |
* @return array Post Types |
| 110 |
*/ |
| 111 |
function convertkit_get_supported_post_types() { |
| 112 |
|
| 113 |
// Define supported Post Types. |
| 114 |
$post_types = array( |
| 115 |
'page', |
| 116 |
'post', |
| 117 |
); |
| 118 |
|
| 119 |
// If public Custom Post Types can be fetched, include them now. |
| 120 |
if ( function_exists( 'get_post_types' ) ) { |
| 121 |
// Get public Custom Post Types. |
| 122 |
$custom_post_types = (array) get_post_types( |
| 123 |
array( |
| 124 |
'public' => true, |
| 125 |
|
| 126 |
// Don't include WordPress' built in Post Types, such as attachment, revisino and nav_menu_item. |
| 127 |
'_builtin' => false, |
| 128 |
) |
| 129 |
); |
| 130 |
|
| 131 |
$post_types = array_merge( |
| 132 |
$post_types, |
| 133 |
array_keys( $custom_post_types ) |
| 134 |
); |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Defines the Post Types that support ConvertKit Forms. |
| 139 |
* |
| 140 |
* @since 1.9.6 |
| 141 |
* |
| 142 |
* @param array $post_types Post Types |
| 143 |
*/ |
| 144 |
$post_types = apply_filters( 'convertkit_get_supported_post_types', $post_types ); |
| 145 |
|
| 146 |
return $post_types; |
| 147 |
|
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Helper method to get supported Post Types for Restricted Content (Member's Content) |
| 152 |
* |
| 153 |
* @since 2.1.0 |
| 154 |
* |
| 155 |
* @deprecated 2.4.3 No longer used by internal code and not recommended. Use `convertkit_get_supported_post_types` instead. |
| 156 |
* |
| 157 |
* @return array Post Types |
| 158 |
*/ |
| 159 |
function convertkit_get_supported_restrict_content_post_types() { |
| 160 |
|
| 161 |
return convertkit_get_supported_post_types(); |
| 162 |
|
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Helper method to get registered Shortcodes. |
| 167 |
* |
| 168 |
* @since 1.9.6.5 |
| 169 |
* |
| 170 |
* @return array Shortcodes |
| 171 |
*/ |
| 172 |
function convertkit_get_shortcodes() { |
| 173 |
|
| 174 |
$shortcodes = array(); |
| 175 |
|
| 176 |
/** |
| 177 |
* Registers shortcodes for the ConvertKit Plugin. |
| 178 |
* |
| 179 |
* @since 1.9.6.5 |
| 180 |
* |
| 181 |
* @param array $shortcodes Shortcodes |
| 182 |
*/ |
| 183 |
$shortcodes = apply_filters( 'convertkit_shortcodes', $shortcodes ); |
| 184 |
|
| 185 |
return $shortcodes; |
| 186 |
|
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Helper method to get registered Blocks. |
| 191 |
* |
| 192 |
* @since 1.9.6 |
| 193 |
* |
| 194 |
* @return array Blocks |
| 195 |
*/ |
| 196 |
function convertkit_get_blocks() { |
| 197 |
|
| 198 |
$blocks = array(); |
| 199 |
|
| 200 |
/** |
| 201 |
* Registers blocks for the ConvertKit Plugin. |
| 202 |
* |
| 203 |
* @since 1.9.6 |
| 204 |
* |
| 205 |
* @param array $blocks Blocks |
| 206 |
*/ |
| 207 |
$blocks = apply_filters( 'convertkit_blocks', $blocks ); |
| 208 |
|
| 209 |
return $blocks; |
| 210 |
|
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Helper method to get registered Block formatters for Gutenberg. |
| 215 |
* |
| 216 |
* @since 2.2.0 |
| 217 |
* |
| 218 |
* @return array Block formatters |
| 219 |
*/ |
| 220 |
function convertkit_get_block_formatters() { |
| 221 |
|
| 222 |
$block_formatters = array(); |
| 223 |
|
| 224 |
/** |
| 225 |
* Registers block formatters in Gutenberg for the ConvertKit Plugin. |
| 226 |
* |
| 227 |
* @since 2.2.0 |
| 228 |
* |
| 229 |
* @param array $block_formatters Block formatters. |
| 230 |
*/ |
| 231 |
$block_formatters = apply_filters( 'convertkit_get_block_formatters', $block_formatters ); |
| 232 |
|
| 233 |
return $block_formatters; |
| 234 |
|
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Helper method to get registered pre-publish actions. |
| 239 |
* |
| 240 |
* @since 2.4.0 |
| 241 |
* |
| 242 |
* @return array Pre-publish actions |
| 243 |
*/ |
| 244 |
function convertkit_get_pre_publish_actions() { |
| 245 |
|
| 246 |
$pre_publish_actions = array(); |
| 247 |
|
| 248 |
/** |
| 249 |
* Registers pre-publish actions for the ConvertKit Plugin. |
| 250 |
* |
| 251 |
* @since 2.4.0 |
| 252 |
* |
| 253 |
* @param array $pre_publish_panels Pre-publish actions. |
| 254 |
*/ |
| 255 |
$pre_publish_actions = apply_filters( 'convertkit_get_pre_publish_actions', $pre_publish_actions ); |
| 256 |
|
| 257 |
return $pre_publish_actions; |
| 258 |
|
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* Helper method to return the Plugin Settings Link |
| 263 |
* |
| 264 |
* @since 1.9.6 |
| 265 |
* |
| 266 |
* @param array $query_args Optional Query Args. |
| 267 |
* @return string Settings Link |
| 268 |
*/ |
| 269 |
function convertkit_get_settings_link( $query_args = array() ) { |
| 270 |
|
| 271 |
$query_args = array_merge( |
| 272 |
$query_args, |
| 273 |
array( |
| 274 |
'page' => '_wp_convertkit_settings', |
| 275 |
) |
| 276 |
); |
| 277 |
|
| 278 |
return add_query_arg( $query_args, admin_url( 'options-general.php' ) ); |
| 279 |
|
| 280 |
} |
| 281 |
|
| 282 |
/** |
| 283 |
* Helper method to return the Plugin Settings Link |
| 284 |
* |
| 285 |
* @since 2.2.4 |
| 286 |
* |
| 287 |
* @param array $query_args Optional Query Args. |
| 288 |
* @return string Settings Link |
| 289 |
*/ |
| 290 |
function convertkit_get_setup_wizard_plugin_link( $query_args = array() ) { |
| 291 |
|
| 292 |
$query_args = array_merge( |
| 293 |
$query_args, |
| 294 |
array( |
| 295 |
'page' => 'convertkit-setup', |
| 296 |
) |
| 297 |
); |
| 298 |
|
| 299 |
return add_query_arg( $query_args, admin_url( 'options.php' ) ); |
| 300 |
|
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* Helper method to return the URL the user needs to visit to register a ConvertKit account. |
| 305 |
* |
| 306 |
* @since 1.9.8.4 |
| 307 |
* |
| 308 |
* @return string ConvertKit Registration URL. |
| 309 |
*/ |
| 310 |
function convertkit_get_registration_url() { |
| 311 |
|
| 312 |
return add_query_arg( |
| 313 |
array( |
| 314 |
'utm_source' => 'wordpress', |
| 315 |
'utm_term' => get_locale(), |
| 316 |
'utm_content' => 'convertkit', |
| 317 |
), |
| 318 |
'https://app.kit.com/users/signup' |
| 319 |
); |
| 320 |
|
| 321 |
} |
| 322 |
|
| 323 |
/** |
| 324 |
* Helper method to return the URL the user needs to visit to sign in to their ConvertKit account. |
| 325 |
* |
| 326 |
* @since 1.9.6.1 |
| 327 |
* |
| 328 |
* @return string ConvertKit Login URL. |
| 329 |
*/ |
| 330 |
function convertkit_get_sign_in_url() { |
| 331 |
|
| 332 |
return add_query_arg( |
| 333 |
array( |
| 334 |
'utm_source' => 'wordpress', |
| 335 |
'utm_term' => get_locale(), |
| 336 |
'utm_content' => 'convertkit', |
| 337 |
), |
| 338 |
'https://app.kit.com/' |
| 339 |
); |
| 340 |
|
| 341 |
} |
| 342 |
|
| 343 |
/** |
| 344 |
* Helper method to return the URL the user needs to visit to manage thier billing. |
| 345 |
* |
| 346 |
* @since 2.2.7 |
| 347 |
* |
| 348 |
* @return string ConvertKit Billing URL. |
| 349 |
*/ |
| 350 |
function convertkit_get_billing_url() { |
| 351 |
|
| 352 |
return add_query_arg( |
| 353 |
array( |
| 354 |
'utm_source' => 'wordpress', |
| 355 |
'utm_term' => get_locale(), |
| 356 |
'utm_content' => 'convertkit', |
| 357 |
), |
| 358 |
'https://app.kit.com/account_settings/billing/' |
| 359 |
); |
| 360 |
|
| 361 |
} |
| 362 |
|
| 363 |
/** |
| 364 |
* Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page. |
| 365 |
* |
| 366 |
* @since 2.2.3 |
| 367 |
* |
| 368 |
* @return string ConvertKit App URL |
| 369 |
*/ |
| 370 |
function convertkit_get_new_form_url() { |
| 371 |
|
| 372 |
return add_query_arg( |
| 373 |
array( |
| 374 |
'utm_source' => 'wordpress', |
| 375 |
'utm_term' => get_locale(), |
| 376 |
'utm_content' => 'convertkit', |
| 377 |
), |
| 378 |
'https://app.kit.com/forms/new/' |
| 379 |
); |
| 380 |
|
| 381 |
} |
| 382 |
|
| 383 |
/** |
| 384 |
* Helper method to return the URL the user needs to visit to edit ConvertKit forms. |
| 385 |
* |
| 386 |
* @since 2.2.3 |
| 387 |
* |
| 388 |
* @return string ConvertKit Form Editor URL. |
| 389 |
*/ |
| 390 |
function convertkit_get_form_editor_url() { |
| 391 |
|
| 392 |
return add_query_arg( |
| 393 |
array( |
| 394 |
'utm_source' => 'wordpress', |
| 395 |
'utm_term' => get_locale(), |
| 396 |
'utm_content' => 'convertkit', |
| 397 |
), |
| 398 |
'https://app.kit.com/forms' |
| 399 |
); |
| 400 |
|
| 401 |
} |
| 402 |
|
| 403 |
/** |
| 404 |
* Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Landing Page. |
| 405 |
* |
| 406 |
* @since 2.5.5 |
| 407 |
* |
| 408 |
* @return string ConvertKit App URL |
| 409 |
*/ |
| 410 |
function convertkit_get_new_landing_page_url() { |
| 411 |
|
| 412 |
return add_query_arg( |
| 413 |
array( |
| 414 |
'utm_source' => 'wordpress', |
| 415 |
'utm_term' => get_locale(), |
| 416 |
'utm_content' => 'convertkit', |
| 417 |
), |
| 418 |
'https://app.kit.com/pages/new/' |
| 419 |
); |
| 420 |
|
| 421 |
} |
| 422 |
|
| 423 |
/** |
| 424 |
* Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Tag. |
| 425 |
* |
| 426 |
* @since 2.3.3 |
| 427 |
* |
| 428 |
* @return string ConvertKit App URL. |
| 429 |
*/ |
| 430 |
function convertkit_get_new_tag_url() { |
| 431 |
|
| 432 |
return add_query_arg( |
| 433 |
array( |
| 434 |
'utm_source' => 'wordpress', |
| 435 |
'utm_term' => get_locale(), |
| 436 |
'utm_content' => 'convertkit', |
| 437 |
), |
| 438 |
'https://app.kit.com/subscribers/' |
| 439 |
); |
| 440 |
|
| 441 |
} |
| 442 |
|
| 443 |
/** |
| 444 |
* Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Broadcast. |
| 445 |
* |
| 446 |
* @since 2.2.6 |
| 447 |
* |
| 448 |
* @return string ConvertKit App URL. |
| 449 |
*/ |
| 450 |
function convertkit_get_new_broadcast_url() { |
| 451 |
|
| 452 |
return add_query_arg( |
| 453 |
array( |
| 454 |
'utm_source' => 'wordpress', |
| 455 |
'utm_term' => get_locale(), |
| 456 |
'utm_content' => 'convertkit', |
| 457 |
), |
| 458 |
'https://app.kit.com/campaigns/' |
| 459 |
); |
| 460 |
|
| 461 |
} |
| 462 |
|
| 463 |
/** |
| 464 |
* Helper method to return the URL the user needs to visit on the ConvertKit app to edit a draft Broadcast. |
| 465 |
* |
| 466 |
* @since 2.4.0 |
| 467 |
* |
| 468 |
* @param int $broadcast_id ConvertKit Broadcast ID. |
| 469 |
* @return string ConvertKit App URL. |
| 470 |
*/ |
| 471 |
function convertkit_get_edit_broadcast_url( $broadcast_id ) { |
| 472 |
|
| 473 |
return add_query_arg( |
| 474 |
array( |
| 475 |
'utm_source' => 'wordpress', |
| 476 |
'utm_term' => get_locale(), |
| 477 |
'utm_content' => 'convertkit', |
| 478 |
), |
| 479 |
sprintf( |
| 480 |
'https://app.kit.com/campaigns/%s/draft', |
| 481 |
$broadcast_id |
| 482 |
) |
| 483 |
); |
| 484 |
|
| 485 |
} |
| 486 |
|
| 487 |
/** |
| 488 |
* Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Product. |
| 489 |
* |
| 490 |
* @since 2.2.3 |
| 491 |
* |
| 492 |
* @return string ConvertKit App URL. |
| 493 |
*/ |
| 494 |
function convertkit_get_new_product_url() { |
| 495 |
|
| 496 |
return add_query_arg( |
| 497 |
array( |
| 498 |
'utm_source' => 'wordpress', |
| 499 |
'utm_term' => get_locale(), |
| 500 |
'utm_content' => 'convertkit', |
| 501 |
), |
| 502 |
'https://app.kit.com/products/new/' |
| 503 |
); |
| 504 |
|
| 505 |
} |
| 506 |
|
| 507 |
/** |
| 508 |
* Helper method to enqueue Select2 scripts for use within the ConvertKit Plugin. |
| 509 |
* |
| 510 |
* @since 1.9.6.4 |
| 511 |
*/ |
| 512 |
function convertkit_select2_enqueue_scripts() { |
| 513 |
|
| 514 |
wp_enqueue_script( 'convertkit-select2', 'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, false ); |
| 515 |
wp_enqueue_script( 'convertkit-admin-select2', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/select2.js', array( 'convertkit-select2' ), CONVERTKIT_PLUGIN_VERSION, false ); |
| 516 |
|
| 517 |
} |
| 518 |
|
| 519 |
/** |
| 520 |
* Helper method to enqueue Select2 stylesheets for use within the ConvertKit Plugin. |
| 521 |
* |
| 522 |
* @since 1.9.6.4 |
| 523 |
*/ |
| 524 |
function convertkit_select2_enqueue_styles() { |
| 525 |
|
| 526 |
wp_enqueue_style( 'convertkit-select2', 'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css', array(), CONVERTKIT_PLUGIN_VERSION ); |
| 527 |
wp_enqueue_style( 'convertkit-admin-select2', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/select2.css', array(), CONVERTKIT_PLUGIN_VERSION ); |
| 528 |
|
| 529 |
} |
| 530 |
|
| 531 |
/** |
| 532 |
* Return the contents of the given local file. |
| 533 |
* |
| 534 |
* @since 2.2.2 |
| 535 |
* |
| 536 |
* @param string $local_file Local file, including path. |
| 537 |
* @return string File contents. |
| 538 |
*/ |
| 539 |
function convertkit_get_file_contents( $local_file ) { |
| 540 |
|
| 541 |
// Bail if the file doesn't exist. |
| 542 |
if ( ! file_exists( $local_file ) ) { |
| 543 |
return ''; |
| 544 |
} |
| 545 |
|
| 546 |
// Read file. |
| 547 |
$contents = file_get_contents( $local_file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 548 |
|
| 549 |
// Return an empty string if the contents of the file could not be read. |
| 550 |
if ( ! $contents ) { |
| 551 |
return ''; |
| 552 |
} |
| 553 |
|
| 554 |
// Return file's contents. |
| 555 |
return $contents; |
| 556 |
|
| 557 |
} |
| 558 |
|
| 559 |
/** |
| 560 |
* Returns a dropdown field commonly used for settings, comprising of: |
| 561 |
* - Do not subscribe |
| 562 |
* - Subscribe |
| 563 |
* - Subscribe to Form |
| 564 |
* |
| 565 |
* @since 2.5.2 |
| 566 |
* |
| 567 |
* @param string $name Field name. |
| 568 |
* @param string $value Field value. |
| 569 |
* @param string $id Field ID attribute. |
| 570 |
* @param string $css_class Field CSS class(es). |
| 571 |
* @param string $context Resource context. |
| 572 |
* @param bool|array $additional_options Additional <option> key/value pairs. |
| 573 |
*/ |
| 574 |
function convertkit_get_subscription_dropdown_field( $name, $value, $id, $css_class = '', $context = '', $additional_options = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter |
| 575 |
|
| 576 |
// Load resource classes. |
| 577 |
$forms = new ConvertKit_Resource_Forms( $context ); |
| 578 |
$tags = new ConvertKit_Resource_Tags( $context ); |
| 579 |
$sequences = new ConvertKit_Resource_Sequences( $context ); |
| 580 |
|
| 581 |
ob_start(); |
| 582 |
include CONVERTKIT_PLUGIN_PATH . '/views/backend/subscription-dropdown-field.php'; |
| 583 |
$output = trim( ob_get_clean() ); |
| 584 |
|
| 585 |
// Return output. |
| 586 |
return $output; |
| 587 |
|
| 588 |
} |
| 589 |
|
| 590 |
/** |
| 591 |
* Helper method to safely call get_current_screen(), returning false |
| 592 |
* if the function is not available or returns null. |
| 593 |
* |
| 594 |
* Otherwise returns the given WP_Screen property. |
| 595 |
* |
| 596 |
* @since 2.5.9 |
| 597 |
* |
| 598 |
* @param string $property WP_Screen property to return. |
| 599 |
* @return bool|string |
| 600 |
*/ |
| 601 |
function convertkit_get_current_screen( $property ) { |
| 602 |
|
| 603 |
// Bail if we cannot determine the screen. |
| 604 |
if ( ! function_exists( 'get_current_screen' ) ) { |
| 605 |
return false; |
| 606 |
} |
| 607 |
|
| 608 |
// Get screen. |
| 609 |
$screen = get_current_screen(); |
| 610 |
|
| 611 |
// Bail if the screen couldn't be determined. |
| 612 |
if ( is_null( $screen ) ) { |
| 613 |
return false; |
| 614 |
} |
| 615 |
|
| 616 |
// Return property. |
| 617 |
return $screen->$property; |
| 618 |
|
| 619 |
} |
| 620 |
|
| 621 |
/** |
| 622 |
* Outputs the Intercom help widget script. |
| 623 |
* |
| 624 |
* @since 2.7.2 |
| 625 |
*/ |
| 626 |
function convertkit_output_intercom_messenger() { |
| 627 |
|
| 628 |
?> |
| 629 |
<script> |
| 630 |
const KIT_INTERCOM_APP_ID = 'e4n3xtxz'; |
| 631 |
window.intercomSettings = { |
| 632 |
api_base: 'https://api-iam.intercom.io', |
| 633 |
app_id: KIT_INTERCOM_APP_ID |
| 634 |
}; |
| 635 |
</script> |
| 636 |
|
| 637 |
<script> |
| 638 |
(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/' + KIT_INTERCOM_APP_ID;var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s, x);};if(document.readyState==='complete'){l();}else if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})(); |
| 639 |
</script> |
| 640 |
<?php |
| 641 |
|
| 642 |
} |
| 643 |
|
| 644 |
/** |
| 645 |
* Returns permitted HTML output when using wp_kses( ..., convertkit_kses_allowed_html()). |
| 646 |
* |
| 647 |
* @since 2.8.5 |
| 648 |
*/ |
| 649 |
function convertkit_kses_allowed_html() { |
| 650 |
|
| 651 |
// Get WordPress' permitted HTML elements. |
| 652 |
$elements = wp_kses_allowed_html( 'post' ); |
| 653 |
|
| 654 |
// Add form elements. |
| 655 |
$form_elements = array( |
| 656 |
'input' => array( |
| 657 |
'type' => true, |
| 658 |
'id' => true, |
| 659 |
'name' => true, |
| 660 |
'class' => true, |
| 661 |
'value' => true, |
| 662 |
'checked' => true, |
| 663 |
'min' => true, |
| 664 |
'max' => true, |
| 665 |
'step' => true, |
| 666 |
'data-*' => true, |
| 667 |
), |
| 668 |
'select' => array( |
| 669 |
'id' => true, |
| 670 |
'name' => true, |
| 671 |
'class' => true, |
| 672 |
'size' => true, |
| 673 |
'multiple' => true, |
| 674 |
'data-*' => true, |
| 675 |
), |
| 676 |
'option' => array( |
| 677 |
'value' => true, |
| 678 |
'selected' => true, |
| 679 |
'data-*' => true, |
| 680 |
), |
| 681 |
'optgroup' => array( |
| 682 |
'label' => true, |
| 683 |
'data-*' => true, |
| 684 |
), |
| 685 |
'label' => array( |
| 686 |
'for' => true, |
| 687 |
), |
| 688 |
); |
| 689 |
|
| 690 |
return array_merge( $elements, $form_elements ); |
| 691 |
|
| 692 |
} |
| 693 |
|
| 694 |
/** |
| 695 |
* Saves the new access token, refresh token and its expiry, and schedules |
| 696 |
* a WordPress Cron event to refresh the token on expiry. |
| 697 |
* |
| 698 |
* @since 3.1.1 |
| 699 |
* |
| 700 |
* @param array $result New Access Token, Refresh Token and Expiry. |
| 701 |
* @param string $client_id OAuth Client ID used for the Access and Refresh Tokens. |
| 702 |
*/ |
| 703 |
function convertkit_maybe_update_credentials( $result, $client_id ) { |
| 704 |
|
| 705 |
// Don't save these credentials if they're not for this Client ID. |
| 706 |
// They're for another Kit Plugin that uses OAuth. |
| 707 |
if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) { |
| 708 |
return; |
| 709 |
} |
| 710 |
|
| 711 |
$settings = new ConvertKit_Settings(); |
| 712 |
$settings->update_credentials( $result ); |
| 713 |
|
| 714 |
} |
| 715 |
|
| 716 |
/** |
| 717 |
* Deletes the stored access token, refresh token and its expiry from the Plugin settings, |
| 718 |
* and clears any existing scheduled WordPress Cron event to refresh the token on expiry, |
| 719 |
* when either: |
| 720 |
* - The access token is invalid |
| 721 |
* - The access token expired, and refreshing failed |
| 722 |
* |
| 723 |
* @since 3.1.1 |
| 724 |
* |
| 725 |
* @param WP_Error $result Error result. |
| 726 |
* @param string $client_id OAuth Client ID used for the Access and Refresh Tokens. |
| 727 |
*/ |
| 728 |
function convertkit_maybe_delete_credentials( $result, $client_id ) { |
| 729 |
|
| 730 |
// Don't save these credentials if they're not for this Client ID. |
| 731 |
// They're for another Kit Plugin that uses OAuth. |
| 732 |
if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) { |
| 733 |
return; |
| 734 |
} |
| 735 |
|
| 736 |
// Persist an error notice in the WordPress Administration until the user fixes the problem. |
| 737 |
WP_ConvertKit()->get_class( 'admin_notices' )->add( 'authorization_failed' ); |
| 738 |
|
| 739 |
$settings = new ConvertKit_Settings(); |
| 740 |
$settings->delete_credentials(); |
| 741 |
|
| 742 |
} |
| 743 |
|
| 744 |
// Update Access Token when refreshed by the API class. |
| 745 |
add_action( 'convertkit_api_get_access_token', 'convertkit_maybe_update_credentials', 10, 2 ); |
| 746 |
add_action( 'convertkit_api_refresh_token', 'convertkit_maybe_update_credentials', 10, 2 ); |
| 747 |
|
| 748 |
// Delete credentials if the API class uses a invalid access token. |
| 749 |
// This prevents the Plugin making repetitive API requests that will 401. |
| 750 |
add_action( 'convertkit_api_access_token_invalid', 'convertkit_maybe_delete_credentials', 10, 2 ); |
| 751 |
|