: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @author Advanced Ads <info@wpadvancedads.com>
namespace AdvancedAds\Admin\Pages;
use Advanced_Ads_Placements;
use AdvancedAds\Framework\Utilities\Params;
use AdvancedAds\Interfaces\Screen_Interface;
use AdvancedAds\Utilities\WordPress;
defined( 'ABSPATH' ) || exit;
class Placements implements Screen_Interface {
* Register screen into WordPress admin area.
public function register_screen(): void {
__( 'Ad Placements', 'advanced-ads' ),
__( 'Placements', 'advanced-ads' ),
WordPress::user_cap( 'advanced_ads_manage_placements' ),
ADVADS_SLUG . '-placements',
* Display screen content.
public function display(): void {
$placement_types = Advanced_Ads_Placements::get_placement_types();
$placements = Advanced_Ads::get_ad_placements_array(); // -TODO use model
$orderby = $this->get_field_to_order_placement();
$has_placements = isset( $placements ) && is_array( $placements ) && count( $placements );
include ADVADS_ABSPATH . 'views/admin/screens/placements.php';
private function get_field_to_order_placement(): string {
$settings = Advanced_Ads_Admin::get_admin_settings();
$default = $settings['placement-orderby'] ?? 'type';
$current = Params::get( 'orderby', $default );
if ( ! in_array( $current, [ 'name', 'type' ], true ) ) {
$settings['placement-orderby'] = $current;
Advanced_Ads_Admin::update_admin_setttings( $settings );
* @param array $placement_types Types of placements.
* @param array $placement Placement instance.
public static function render_order_data( $placement_types, $placement ): void {
'order' => absint( $placement_types[ $placement['type'] ]['order'] ?? 100 ),
'name' => esc_html( $placement['name'] ),
'type' => esc_html( $placement['type'] ),
'words-between-repeats' => ! empty( $placement['options']['words_between_repeats'] ) ? 1 : 0,
'post-content-index' => absint( $placement['options']['index'] ?? 0 ),
private function get_url_for_content_placement_picker(): string {
if ( get_option( 'show_on_front' ) === 'posts' ) {
$recent_posts = wp_get_recent_posts(
'post_status' => 'publish',
$location = get_permalink( $recent_posts[0] );
return $location ? $location : home_url();