checkEnqueueStyles(); add_action( 'wp_ajax_pys_optin_add', [$this,'pys_optin_add']); add_action( 'wp_ajax_nopriv_pys_optin_add', [$this,'pys_optin_add']); add_action( 'admin_notices', [$this,'adminRenderOptinNotices'], 1 ); } function pys_optin_add() { $body = array( 'action' => 'optin_add', 'data' => $_POST ); $response = wp_remote_post( 'https://www.pixelyoursite.com', array( 'timeout' => 30, 'sslverify' => false, 'user-agent' => 'PixelYourSite/' . PYS_FREE_VERSION . '; ' . get_bloginfo( 'url' ), 'body' => $body ) ); if (is_wp_error($response)) { wp_send_json_error(null, 420); } else { $body = wp_remote_retrieve_body($response); $decoded_body = json_decode($body, true); // Decode the body to an array if (isset($decoded_body['data'])) { wp_send_json_success($decoded_body['data']); // Return only the 'data' part } else { wp_send_json_error('Invalid response format', 422); } } } function adminRenderOptinNotices() { $user = wp_get_current_user(); $user_id = $user->ID; // never show again for opted-in users if ( get_option( 'pys_core_opted_in_dismissed_at' ) || get_user_meta( $user_id, 'pys_core_opted_in_dismissed_at', true ) ) { return; } $first_time_dismissed_at = get_option( 'pys_core_optin_first_time_dismissed_at' ) ?? get_user_meta( $user_id, 'pys_core_optin_first_time_dismissed_at', true ); $second_time_dismissed_at = get_option( 'pys_core_optin_second_time_dismissed_at' ) ?? get_user_meta( $user_id, 'pys_core_optin_second_time_dismissed_at', true ); if ($second_time_dismissed_at) { /*$month_ago = time() - MONTH_IN_SECONDS; if ( $month_ago < $second_time_dismissed_at ) { return; } $header = 'Free PIXELYOURSITE HACKS: Improve your ads return and website tracking - LAST CALL'; $dismiss_key = 'optin_third_time';*/ return; } if ( $first_time_dismissed_at ) { $week_ago = time() - WEEK_IN_SECONDS; if ( $week_ago < $first_time_dismissed_at ) { return; // hide if dismissed less then week ago } $header = 'PIXELYOURSITE HACKS: Improve your ads return and website tracking with FREE Facebook, Google and Pinterest hacks'; $dismiss_key = 'optin_second_time'; } else { // was never dismissed $header = 'Free PIXELYOURSITE HACKS: Improve your ads return and website tracking'; $dismiss_key = 'optin_first_time'; } ?>