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/clone/wp-conte.../plugins/advanced.../modules/pef
File: class-module.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* PEF module
[2] Fix | Delete
*
[3] Fix | Delete
* @package AdvancedAds
[4] Fix | Delete
* @author Advanced Ads <info@wpadvancedads.com>
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
namespace AdvancedAds\Modules\ProductExperimentationFramework;
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Module main class
[11] Fix | Delete
*/
[12] Fix | Delete
class Module {
[13] Fix | Delete
/**
[14] Fix | Delete
* Current running features
[15] Fix | Delete
*
[16] Fix | Delete
* @var array[]
[17] Fix | Delete
*/
[18] Fix | Delete
const FEATURES = [
[19] Fix | Delete
'labs-video-ads' => [
[20] Fix | Delete
'name' => 'Video Ads',
[21] Fix | Delete
'weight' => 1,
[22] Fix | Delete
'text' => 'The Advanced Ads team is developing a new feature to support video ads. This enables embedding videos from your WordPress media library and video ad networks. Like image ads, they would be fully compatible with all conditions and placements. We are curious whether our users want us to prioritize this feature.',
[23] Fix | Delete
],
[24] Fix | Delete
'labs-email-notifications' => [
[25] Fix | Delete
'name' => 'Email Notifications',
[26] Fix | Delete
'weight' => 1,
[27] Fix | Delete
'text' => 'The Advanced Ads team is developing a new feature to improve email notifications. Imagine receiving timely reminders in your inbox, giving you ample time to take action. Whether renewing an ad, adjusting ad groups, or checking the statistics after a campaign has ended, you’ll be in the know every step of the way. We are curious whether our users want us to prioritize this feature.',
[28] Fix | Delete
],
[29] Fix | Delete
'labs-image-mapping' => [
[30] Fix | Delete
'name' => 'Image Mapping',
[31] Fix | Delete
'weight' => 1,
[32] Fix | Delete
'text' => 'The Advanced Ads team is developing a new feature to allow serving multiple images with the same ad unit. This workflow can save you time in certain setups and is an alternative to ad groups when it comes to multiple campaigns from the same advertiser. We are curious whether our users want us to prioritize this feature.',
[33] Fix | Delete
],
[34] Fix | Delete
'labs-automated-split-tests' => [
[35] Fix | Delete
'name' => 'Automated Split Tests',
[36] Fix | Delete
'weight' => 1,
[37] Fix | Delete
'text' => 'The Advanced Ads team is working on a new feature to simplify your workload: automated split testing. Let us handle the heavy lifting for you by automatically maximizing your ad performance based on the CTR of your ad units. We are curious whether our users want us to prioritize this feature.',
[38] Fix | Delete
],
[39] Fix | Delete
'labs-ad-preview' => [
[40] Fix | Delete
'name' => 'Ad Preview',
[41] Fix | Delete
'weight' => 1,
[42] Fix | Delete
'text' => 'The Advanced Ads team is developing a new feature: ad previews. Simply input the code in the Parameter box, and watch your ad come to life on the Edit Ad page. We are curious whether our users want us to prioritize this feature.',
[43] Fix | Delete
],
[44] Fix | Delete
'labs-animated-ads' => [
[45] Fix | Delete
'name' => 'Animated Ads',
[46] Fix | Delete
'weight' => 1,
[47] Fix | Delete
'text' => 'The Advanced Ads team is developing a new feature to allow animating ads. Captivate your audience with eye-catching effects like flip, slider, and fade. Enhance engagement and leave a lasting impression with dynamic ad displays. We are curious whether our users want us to prioritize this feature.',
[48] Fix | Delete
],
[49] Fix | Delete
'labs-active-view-tracking' => [
[50] Fix | Delete
'name' => 'Active View Tracking',
[51] Fix | Delete
'weight' => 1,
[52] Fix | Delete
'text' => 'The Advanced Ads team is developing a new feature to enable active view tracking. Gain precise insights into ad viewability and upgrade your metrics. With active view tracking, you’ll know if your ad is loaded and visible in the viewport. We are curious whether our users want us to prioritize this feature.',
[53] Fix | Delete
],
[54] Fix | Delete
'labs-ad-schedule-wizard' => [
[55] Fix | Delete
'name' => 'Ad Schedule Wizard',
[56] Fix | Delete
'weight' => 1,
[57] Fix | Delete
'text' => 'The Advanced Ads team is developing a better ad scheduling and planning interface. Simplify your workflow and maximize efficiency. With an improved user experience, managing your ads could be easier than ever. We are curious whether our users want us to prioritize this feature.',
[58] Fix | Delete
],
[59] Fix | Delete
'labs-reports-insights' => [
[60] Fix | Delete
'name' => 'Reports & Insights',
[61] Fix | Delete
'weight' => 1,
[62] Fix | Delete
'text' => 'The Advanced Ads team is improving the reporting. Customize your email reports to focus on the metrics that most matter to you and easily share them as PDFs. Empower yourself with actionable data and streamline communication with stakeholders. We are curious whether our users want us to prioritize this feature.',
[63] Fix | Delete
],
[64] Fix | Delete
];
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* User meta key where the dismiss flag is stored.
[68] Fix | Delete
*
[69] Fix | Delete
* @var string
[70] Fix | Delete
*/
[71] Fix | Delete
const USER_META = 'advanced_ads_pef_dismiss';
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* The singleton
[75] Fix | Delete
*
[76] Fix | Delete
* @var Module
[77] Fix | Delete
*/
[78] Fix | Delete
private static $instance;
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Sum of all weights
[82] Fix | Delete
*
[83] Fix | Delete
* @var int
[84] Fix | Delete
*/
[85] Fix | Delete
private $weight_sum = 0;
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* ID => weight association
[89] Fix | Delete
*
[90] Fix | Delete
* @var int[]
[91] Fix | Delete
*/
[92] Fix | Delete
private $weights = [];
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Whether the PEF can be displayed based on user meta
[96] Fix | Delete
*
[97] Fix | Delete
* @var bool
[98] Fix | Delete
*/
[99] Fix | Delete
private $can_display = true;
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* Private constructor
[103] Fix | Delete
*/
[104] Fix | Delete
private function __construct() {
[105] Fix | Delete
// Wait for `admin_init` to get the current user.
[106] Fix | Delete
add_action( 'admin_init', [ $this, 'admin_init' ] );
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* Initialization
[111] Fix | Delete
*
[112] Fix | Delete
* @return void
[113] Fix | Delete
*/
[114] Fix | Delete
public function admin_init() {
[115] Fix | Delete
$meta = get_user_meta( get_current_user_id(), self::USER_META, true );
[116] Fix | Delete
if ( $this->get_minor_version( ADVADS_VERSION ) === $this->get_minor_version( $meta ) ) {
[117] Fix | Delete
$this->can_display = false;
[118] Fix | Delete
[119] Fix | Delete
return;
[120] Fix | Delete
}
[121] Fix | Delete
$this->collect_weights();
[122] Fix | Delete
add_action( 'wp_ajax_advanced_ads_pef', [ $this, 'dismiss' ] );
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Ajax action to hie PEF for the current user until next plugin update
[127] Fix | Delete
*
[128] Fix | Delete
* @return void
[129] Fix | Delete
*/
[130] Fix | Delete
public function dismiss() {
[131] Fix | Delete
if ( ! check_ajax_referer( 'advanced_ads_pef' ) ) {
[132] Fix | Delete
wp_send_json_error( 'Unauthorized', 401 );
[133] Fix | Delete
}
[134] Fix | Delete
update_user_meta( get_current_user_id(), self::USER_META, ADVADS_VERSION );
[135] Fix | Delete
wp_send_json_success( 'OK', 200 );
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Collect feature ID with their weight as recorded in the class constant. Also calculate the weight sum
[140] Fix | Delete
*/
[141] Fix | Delete
private function collect_weights() {
[142] Fix | Delete
if ( 0 !== $this->weight_sum ) {
[143] Fix | Delete
return;
[144] Fix | Delete
}
[145] Fix | Delete
foreach ( self::FEATURES as $id => $feature ) {
[146] Fix | Delete
$this->weights[ $id ] = (int) $feature['weight'];
[147] Fix | Delete
$this->weight_sum += $this->weights[ $id ];
[148] Fix | Delete
}
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Get a random feature based on weights and a random number
[153] Fix | Delete
*
[154] Fix | Delete
* @return array
[155] Fix | Delete
*/
[156] Fix | Delete
public function get_winner_feature() {
[157] Fix | Delete
$random_weight = mt_rand( 1, $this->weight_sum );
[158] Fix | Delete
$current_weight = 0;
[159] Fix | Delete
foreach ( self::FEATURES as $id => $feature ) {
[160] Fix | Delete
$current_weight += $this->weights[ $id ];
[161] Fix | Delete
if ( $random_weight <= $current_weight ) {
[162] Fix | Delete
return array_merge(
[163] Fix | Delete
[
[164] Fix | Delete
'id' => $id,
[165] Fix | Delete
'weight' => $this->weights[ $id ],
[166] Fix | Delete
],
[167] Fix | Delete
self::FEATURES[ $id ]
[168] Fix | Delete
);
[169] Fix | Delete
}
[170] Fix | Delete
}
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* Render PEF
[175] Fix | Delete
*
[176] Fix | Delete
* @param string $screen the screen on which PEF is displayed, used in the utm_campaign parameter.
[177] Fix | Delete
*
[178] Fix | Delete
* @return void
[179] Fix | Delete
*/
[180] Fix | Delete
public function render( $screen ) {
[181] Fix | Delete
if ( ! $this->can_display ) {
[182] Fix | Delete
return;
[183] Fix | Delete
}
[184] Fix | Delete
$winner = $this->get_winner_feature();
[185] Fix | Delete
require_once DIR . '/views/template.php';
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* Get minor part of a version
[190] Fix | Delete
*
[191] Fix | Delete
* @param string $version version to get the minor part from.
[192] Fix | Delete
*
[193] Fix | Delete
* @return string
[194] Fix | Delete
*/
[195] Fix | Delete
public function get_minor_version( $version ) {
[196] Fix | Delete
return explode( '.', $version )[1] ?? '0';
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Build the link for the winner feature with all its utm parameters
[201] Fix | Delete
*
[202] Fix | Delete
* @param array $winner the winner feature.
[203] Fix | Delete
* @param string $screen the screen on which it was displayed.
[204] Fix | Delete
*
[205] Fix | Delete
* @return string
[206] Fix | Delete
*/
[207] Fix | Delete
public function build_link( $winner, $screen ) {
[208] Fix | Delete
$link = "https://wpadvancedads.com/advanced-ads-labs/?utm_source=advanced-ads&utm_medium=link&utm_campaign=$screen-aa-labs&utm_term=b";
[209] Fix | Delete
$link .= str_replace( '.', '-', ADVADS_VERSION ) . "w{$winner['weight']}-{$this->weight_sum}&utm_content={$winner['id']}";
[210] Fix | Delete
[211] Fix | Delete
return $link;
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
/**
[215] Fix | Delete
* Return the singleton. Create it if needed
[216] Fix | Delete
*
[217] Fix | Delete
* @return Module
[218] Fix | Delete
*/
[219] Fix | Delete
public static function get_instance() {
[220] Fix | Delete
if ( null === self::$instance ) {
[221] Fix | Delete
self::$instance = new self();
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
return self::$instance;
[225] Fix | Delete
}
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function