Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/themify-.../includes/optin-se...
File: base.php
<?php
[0] Fix | Delete
[1] Fix | Delete
defined('ABSPATH') || exit;
[2] Fix | Delete
[3] Fix | Delete
abstract class Builder_Optin_Service {
[4] Fix | Delete
[5] Fix | Delete
public static abstract function get_id():string;
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Provider Name
[9] Fix | Delete
*/
[10] Fix | Delete
public static abstract function get_label(): string;
[11] Fix | Delete
/**
[12] Fix | Delete
* Module options, displayed in the Optin module form
[13] Fix | Delete
*/
[14] Fix | Delete
public static abstract function get_settings():array;
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Provider options that are not unique to each module
[18] Fix | Delete
* These are displayed in the Builder settings page
[19] Fix | Delete
*/
[20] Fix | Delete
public static abstract function get_global_options():array;
[21] Fix | Delete
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Retrieves the $fields_args from module and determines if there is valid form to show.
[25] Fix | Delete
*/
[26] Fix | Delete
public static abstract function validate_data(array $fields_args):string;
[27] Fix | Delete
[28] Fix | Delete
[29] Fix | Delete
protected static function init():void{}
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Checks whether this service is available.
[33] Fix | Delete
*/
[34] Fix | Delete
[35] Fix | Delete
public static function is_available():bool {
[36] Fix | Delete
return true;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Creates or returns an instance of this class.
[41] Fix | Delete
*/
[42] Fix | Delete
public static function run():void {
[43] Fix | Delete
if (is_admin()) {
[44] Fix | Delete
add_action('wp_ajax_tb_optin_clear_cache', array(__CLASS__, 'ajax_clear_cache'));
[45] Fix | Delete
add_action('wp_ajax_tb_optin_subscribe', array(__CLASS__, 'ajax_subscribe'));
[46] Fix | Delete
add_action('wp_ajax_nopriv_tb_optin_subscribe', array(__CLASS__, 'ajax_subscribe'));
[47] Fix | Delete
}
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Initialize data providers for the module
[52] Fix | Delete
*
[53] Fix | Delete
* Other plugins or themes can extend or add to this list
[54] Fix | Delete
* by using the "builder_optin_services" filter.
[55] Fix | Delete
*/
[56] Fix | Delete
private static function init_providers($type = 'all'):array {
[57] Fix | Delete
$coreList=array(
[58] Fix | Delete
'mailchimp' => 'Builder_Optin_Service_MailChimp',
[59] Fix | Delete
'activecampaign' => 'Builder_Optin_Service_ActiveCampaign',
[60] Fix | Delete
'convertkit' => 'Builder_Optin_Service_ConvertKit',
[61] Fix | Delete
'getresponse' => 'Builder_Optin_Service_GetResponse',
[62] Fix | Delete
'mailerlite' => 'Builder_Optin_Service_MailerLite',
[63] Fix | Delete
'newsletter' => 'Builder_Optin_Service_Newsletter',
[64] Fix | Delete
);
[65] Fix | Delete
$providers=[];
[66] Fix | Delete
$providersList = apply_filters('builder_optin_services',$coreList);
[67] Fix | Delete
if ( $type !== 'all' ) {
[68] Fix | Delete
if ( ! isset( $providersList[ $type ] ) ) {
[69] Fix | Delete
return $providers;
[70] Fix | Delete
}
[71] Fix | Delete
$providersList = array( $type => $providersList[ $type ] );
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
$dir = __DIR__ .DIRECTORY_SEPARATOR;
[75] Fix | Delete
[76] Fix | Delete
foreach ( $providersList as $id => $provider ) {
[77] Fix | Delete
$path=isset($coreList[$id])?($dir . $id):$id;
[78] Fix | Delete
include_once( $path . '.php' );
[79] Fix | Delete
if ( class_exists( $provider,false ) && $provider::is_available() ) {
[80] Fix | Delete
$provider::init();
[81] Fix | Delete
$providers[ $id ] = $provider;
[82] Fix | Delete
}
[83] Fix | Delete
}
[84] Fix | Delete
return $providers;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Helper function to retrieve list of providers or provider instance
[89] Fix | Delete
*/
[90] Fix | Delete
public static function get_providers(string $id='all',bool $is_v75=false) {
[91] Fix | Delete
$providers= self::init_providers($id);
[92] Fix | Delete
if($id==='all'){
[93] Fix | Delete
return $providers;
[94] Fix | Delete
}
[95] Fix | Delete
if(!isset($providers[ $id ])){
[96] Fix | Delete
return null;
[97] Fix | Delete
}
[98] Fix | Delete
$class=$providers[ $id ];
[99] Fix | Delete
return $is_v75===true?$class:new $class();
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Handles the Ajax request for subscription form
[104] Fix | Delete
*
[105] Fix | Delete
* Hooked to wp_ajax_tb_optin_subscribe
[106] Fix | Delete
*/
[107] Fix | Delete
public static function ajax_subscribe() {
[108] Fix | Delete
if (!isset($_POST['tb_optin_provider'], $_POST['tb_optin_fname'], $_POST['tb_optin_lname'], $_POST['tb_optin_email'], $_POST['tb_post_id'], $_POST['tb_element_id'])) {
[109] Fix | Delete
wp_send_json_error(array('error' => __('Required fields are empty.', 'themify')));
[110] Fix | Delete
}
[111] Fix | Delete
$module = Themify_Builder_Component_Module::get_element_settings( $_POST['tb_post_id'], $_POST['tb_element_id'] );
[112] Fix | Delete
if ( ! $module ) {
[113] Fix | Delete
die;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
/* CAPTCHA validation */
[117] Fix | Delete
if ( isset( $module['captcha'] ) ) {
[118] Fix | Delete
$provider = $module['captcha'] === 'on' ? 'recaptcha' : 'hcaptcha';
[119] Fix | Delete
$response =
[120] Fix | Delete
$provider === 'recaptcha' && ! empty( $_POST['g-recaptcha-response'] ) ? $_POST['g-recaptcha-response']
[121] Fix | Delete
: ( $provider === 'hcaptcha' && ! empty( $_POST['h-captcha-response'] ) ? $_POST['h-captcha-response'] : null );
[122] Fix | Delete
if ( $response ) {
[123] Fix | Delete
$result = Themify_Builder_Model::validate_captcha( $provider, $response );
[124] Fix | Delete
if ( is_wp_error( $result ) ) {
[125] Fix | Delete
wp_send_json_error( [ 'error' => $result->get_error_message() ] );
[126] Fix | Delete
}
[127] Fix | Delete
} else {
[128] Fix | Delete
wp_send_json_error( [ 'error' => __( 'Empty Captcha response.', 'themify' ) ] );
[129] Fix | Delete
}
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
$data = array();
[133] Fix | Delete
foreach ($_POST as $key => $value) {
[134] Fix | Delete
// remove "tb_optin_" prefix from the $_POST data
[135] Fix | Delete
$key = preg_replace('/^tb_optin_/', '', $key);
[136] Fix | Delete
$data[$key] = sanitize_text_field(trim($value));
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
if ($provider = self::get_providers($data['provider'],true)) {
[140] Fix | Delete
$result = $provider::subscribe($data);
[141] Fix | Delete
if (is_wp_error($result)) {
[142] Fix | Delete
wp_send_json_error(array('error' => $result->get_error_message()));
[143] Fix | Delete
} else {
[144] Fix | Delete
wp_send_json_success(array(
[145] Fix | Delete
/* send name and email in GET, these may come useful when building the page that the visitor will be redirected to */
[146] Fix | Delete
'redirect' => add_query_arg(array(
[147] Fix | Delete
'fname' => $data['fname'],
[148] Fix | Delete
'lname' => $data['lname'],
[149] Fix | Delete
'email' => $data['email'],
[150] Fix | Delete
), $data['redirect'])
[151] Fix | Delete
));
[152] Fix | Delete
}
[153] Fix | Delete
} else {
[154] Fix | Delete
wp_send_json_error(array('error' => __('Unknown provider.', 'themify')));
[155] Fix | Delete
}
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
public static function ajax_clear_cache() {
[159] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[160] Fix | Delete
if (current_user_can('manage_options') && Themify_Access_Role::check_access_backend()) {
[161] Fix | Delete
$providers = self::get_providers('all',true);
[162] Fix | Delete
foreach ($providers as $id => $instance) {
[163] Fix | Delete
$instance::clear_cache();
[164] Fix | Delete
}
[165] Fix | Delete
wp_send_json_success();
[166] Fix | Delete
}
[167] Fix | Delete
wp_send_json_error();
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Returns the value of a setting
[173] Fix | Delete
*/
[174] Fix | Delete
protected static function get($id, $default = null):?string {
[175] Fix | Delete
if ($value = themify_builder_get("setting-{$id}", "setting-{$id}")) {
[176] Fix | Delete
return $value;
[177] Fix | Delete
} else {
[178] Fix | Delete
return $default;
[179] Fix | Delete
}
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
protected static function get_api_key():?string {
[183] Fix | Delete
return static::get(static::get_id() . '_key');
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
/**
[187] Fix | Delete
* Action to perform when Clear Cache is requested
[188] Fix | Delete
*/
[189] Fix | Delete
public static function clear_cache():void {
[190] Fix | Delete
$key = static::get_api_key();
[191] Fix | Delete
if (!empty($key)) {
[192] Fix | Delete
$id = static::get_id();
[193] Fix | Delete
delete_transient('tb_optin_' . $id . '_' . md5($key));
[194] Fix | Delete
Themify_Storage::delete('tb_optin_' . $id . '_' . $key);
[195] Fix | Delete
}
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Get list of provider
[200] Fix | Delete
*
[201] Fix | Delete
* @return string|Array
[202] Fix | Delete
*/
[203] Fix | Delete
protected static function get_lists(?string $key = '') {
[204] Fix | Delete
if ($key === '') {
[205] Fix | Delete
$key = static::get_api_key();
[206] Fix | Delete
}
[207] Fix | Delete
if (empty($key)) {
[208] Fix | Delete
return sprintf(__('%s API Key is missing.', 'themify'), static::get_label());
[209] Fix | Delete
}
[210] Fix | Delete
$id = static::get_id();
[211] Fix | Delete
$cache_key = 'tb_optin_' . $id . '_' . $key;
[212] Fix | Delete
if (false === ( $lists = Themify_Storage::get($cache_key) )) {
[213] Fix | Delete
delete_transient('tb_optin_' . $id . '_' . md5($key));
[214] Fix | Delete
if (is_wp_error(( $data = static::request_list()))) {
[215] Fix | Delete
return $data->get_error_message();
[216] Fix | Delete
}
[217] Fix | Delete
Themify_Storage::set($cache_key, $data, MONTH_IN_SECONDS);
[218] Fix | Delete
return $data;
[219] Fix | Delete
}
[220] Fix | Delete
else {
[221] Fix | Delete
return json_decode($lists, true);
[222] Fix | Delete
}
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
/**
[226] Fix | Delete
* Subscribe visitor to the mailing list
[227] Fix | Delete
*
[228] Fix | Delete
* @param $args array( 'fname', 'lname', 'email' )
[229] Fix | Delete
* it also includes options from get_options() method with their values.
[230] Fix | Delete
*
[231] Fix | Delete
* @return WP_Error|true
[232] Fix | Delete
*/
[233] Fix | Delete
public static function subscribe(array $args) {
[234] Fix | Delete
return true;
[235] Fix | Delete
}
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
Builder_Optin_Service::run();
[239] Fix | Delete
[240] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function