: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Submit only the current group. Submitting the form with all groups could otherwise cause a server timeout or PHP limit error.
* @param {string} modalID
function advads_group_edit_submit( modalID ) {
jQuery( '.advads-ad-group-form' )
.filter( ( i, element ) => ! jQuery( element ).parents( modalID ).length )
* replace textarea with TinyMCE editor for Rich Content ad type
function advads_maybe_textarea_to_tinymce ( ad_type ) {
var textarea = jQuery( '#advads-ad-content-plain' ),
textarea_html = textarea.val(),
tinymce_id = 'advanced-ads-tinymce',
tinymce_id_ws = jQuery( '#' + tinymce_id ),
tinymce_wrapper_div = jQuery( '#advanced-ads-tinymce-wrapper' )
if ( ad_type !== 'content' ) {
tinymce_id_ws.prop( 'name', tinymce_id )
tinymce_wrapper_div.hide()
if ( typeof tinyMCE === 'object' && tinyMCE.get( tinymce_id ) !== null ) {
// see BeforeSetContent in the wp-includes\js\tinymce\plugins\wordpress\plugin.js
hasWpautop = (wp && wp.editor && wp.editor.autop && tinyMCE.get( tinymce_id ).getParam( 'wpautop', true ))
textarea_html = wp.editor.autop( textarea_html )
tinyMCE.get( tinymce_id ).setContent( textarea_html )
tinymce_id_ws.prop( 'name', textarea.prop( 'name' ) )
tinymce_wrapper_div.show()
} else if ( tinymce_id_ws.length ) {
tinymce_id_ws.val( textarea_html )
tinymce_id_ws.prop( 'name', textarea.prop( 'name' ) )
tinymce_wrapper_div.show()
* Show a message depending on whether Adsense Auto ads are enabled.
function advads_show_adsense_auto_ads_warning () {
$msg = jQuery( '.advads-auto-ad-in-ad-content' ).show()
$msg.on( 'click', 'button', function () {
action: 'advads-adsense-enable-pla',
nonce: advadsglobal.ajax_nonce
} ).done( function ( data ) {
$msg.show().html( advadstxt.page_level_ads_enabled )
} ).fail( function ( jqXHR, textStatus ) {
* Check if a third-party ads.txt file exists.
function advads_ads_txt_find_issues () {
var $wrapper = jQuery( '#advads-ads-txt-notice-wrapper' )
var $refresh = jQuery( '#advads-ads-txt-notice-refresh' )
var $actions = jQuery( '.advads-ads-txt-action' )
* Toggle the visibility of the spinner.
* @param {Bool} state True to show, False to hide.
function set_loading ( state ) {
$actions.toggle( ! state )
$wrapper.html( '<span class="spinner advads-spinner"></span>' )
if ( ! $wrapper.length ) {
if ( ! $wrapper.find( 'ul' ).length ) {
// There are no notices. Fetch them using ajax.
$refresh.on('click', function () {
function done ( response ) {
$wrapper.html( response.notices )
function fail ( jqXHR ) {
'<p class="advads-notice-inline advads-error">'
+ jQuery( '#advads-ads-txt-notice-error' ).text().replace( '%s', parseInt( jqXHR.status, 10 ) ),
action: 'advads-ads-txt',
nonce: advadsglobal.ajax_nonce,
} ).done( done ).fail( fail )
jQuery( document ).on( 'click', '#advads-ads-txt-remove-real', function ( event ) {
action: 'advads-ads-txt',
nonce: advadsglobal.ajax_nonce,
type: 'remove_real_file',
done: function ( response ) {
if ( response.additional_content ) {
jQuery( '#advads-ads-txt-additional-content' ).val( response.additional_content )
before_send: function () {
advanced_ads_admin.filesystem.ajax( args )
jQuery( document ).on( 'click', '#advads-ads-txt-create-real', function ( event ) {
action: 'advads-ads-txt',
nonce: advadsglobal.ajax_nonce,
type: 'create_real_file',
before_send: function () {
advanced_ads_admin.filesystem.ajax( args )
window.advanced_ads_admin = window.advanced_ads_admin || {}
advanced_ads_admin.filesystem = {
* Holds the current job while the user writes data in the 'Connection Information' modal.
* Toggle the 'Connection Information' modal.
_requestForCredentialsModalToggle: function () {
this.$filesystemModal.toggle()
jQuery( 'body' ).toggleClass( 'modal-open' )
this._init = function () {}
self.$filesystemModal = jQuery( '#advanced-ads-rfc-dialog' )
self.$filesystemModal.on( 'submit', 'form', function ( event ) {
self.ajax( self._locked_job, true )
self._requestForCredentialsModalToggle()
* Closes the request credentials modal when clicking the 'Cancel' button.
self.$filesystemModal.on( 'click', '[data-js-action="close"]', function () {
if ( jQuery.isPlainObject( self._locked_job ) && self._locked_job.on_modal_close ) {
self._locked_job.on_modal_close()
self._requestForCredentialsModalToggle()
* Sends AJAX request. Shows 'Connection Information' modal if needed.
* @param {bool} skip_modal
ajax: function ( args, skip_modal ) {
if ( ! skip_modal && this.$filesystemModal.length > 0 ) {
this._requestForCredentialsModalToggle()
this.$filesystemModal.find( 'input:enabled:first' ).focus()
username: jQuery( '#username' ).val(),
password: jQuery( '#password' ).val(),
hostname: jQuery( '#hostname' ).val(),
connection_type: jQuery( 'input[name="connection_type"]:checked' ).val(),
public_key: jQuery( '#public_key' ).val(),
private_key: jQuery( '#private_key' ).val(),
_fs_nonce: jQuery( '#_fs_nonce' ).val()
if ( args.before_send ) {
options.data = jQuery.extend( options.data, args.data )
var request = jQuery.ajax( options )
request.done( args.done )
request.fail( args.fail )
window.Advanced_Ads_Admin = window.Advanced_Ads_Admin || {
init_ad_source_editor: function () {
get_ad_source_editor_text: function () {
if ( Advanced_Ads_Admin.editor && Advanced_Ads_Admin.editor.codemirror ) {
text = Advanced_Ads_Admin.editor.codemirror.getValue();
const ta = jQuery( '#advads-ad-content-plain' );
set_ad_source_editor_text: function ( text ) {
if ( Advanced_Ads_Admin.editor && Advanced_Ads_Admin.editor.codemirror ) {
Advanced_Ads_Admin.editor.codemirror.setValue( text )
jQuery( '#advads-ad-content-plain' ).val( text )
check_ad_source: function () {
const text = Advanced_Ads_Admin.get_ad_source_editor_text();
const phpWarning = jQuery( '#advads-parameters-php-warning' );
const allowPhpWarning = jQuery( '#advads-allow-php-warning' );
const plainTextarea = document.getElementById( 'advads-ad-content-plain' );
plainTextarea.value = text;
plainTextarea.dispatchEvent( new Event( 'input' ) );
if ( jQuery( '#advads-parameters-php' ).prop( 'checked' ) ) {
// ad content has opening php tag.
if ( /<\?(?:php|=)/.test( text ) ) {
// execute shortcodes is enabled.
if ( jQuery( '#advads-parameters-shortcodes' ).prop( 'checked' ) && ! /\[[^\]]+\]/.test( text ) ) {
jQuery( '#advads-parameters-shortcodes-warning' ).show();
jQuery( '#advads-parameters-shortcodes-warning' ).hide();
* Change the user id to the current user and save the post.
reassign_ad: function ( user_id ) {
let $authorBox = jQuery( '#post_author_override' );
if ( ! $authorBox.length ) {
$authorBox = jQuery( '#post_author' );
$authorBox.val( user_id ).queue( () => {
jQuery( '#post' ).submit();
* Toggle placement advanced options.
* @deprecated. Used only by add-ons when the base plugin version < 1.19.
toggle_placements_visibility: function ( elm, state ) {
var advadsplacementformrow = jQuery( elm ).next( '.advads-placements-advanced-options' )
var hide = ( typeof state !== 'undefined' ) ? ! state : advadsplacementformrow.is( ':visible' );;
advadsplacementformrow.hide()
jQuery( '#advads-last-edited-placement' ).val( '' )
var placement_id = jQuery( elm ).parents( '.advads-placements-table-options' ).find( '.advads-placement-slug' ).val()
advadsplacementformrow.show()
jQuery( '#advads-last-edited-placement' ).val( placement_id )
// Some special elements (color picker) may not be detected with jquery.
var tr = jQuery( elm ).closest( 'tr.advanced-ads-placement-row' )
tr.data( 'touched', true )
* @param {str} name of the cookie
get_cookie: function (name) {
var i, x, y, ADVcookies = document.cookie.split( ";" );
for (i = 0; i < ADVcookies.length; i++)
x = ADVcookies[i].substr( 0, ADVcookies[i].indexOf( "=" ) );
y = ADVcookies[i].substr( ADVcookies[i].indexOf( "=" ) + 1 );
x = x.replace( /^\s+|\s+$/g, "" );
* @param {str} name of the cookie
* @param {str} value of the cookie
* @param {int} exdays days until cookie expires
* set 0 to expire cookie immidiatelly
* set null to expire cookie in the current session
set_cookie: function (name, value, exdays, path, domain, secure) {
var expiry = ( exdays == null ) ? null : exdays * 24 * 60 * 60;
this.set_cookie_sec( name, value, expiry, path, domain, secure );
* set a cookie with expiry given in seconds
* @param {str} name of the cookie
* @param {str} value of the cookie
* @param {int} expiry seconds until cookie expires
* set 0 to expire cookie immidiatelly
* set null to expire cookie in the current session
set_cookie_sec: function (name, value, expiry, path, domain, secure) {
exdate.setSeconds( exdate.getSeconds() + parseInt( expiry ) );
document.cookie = name + "=" + escape( value ) +
((expiry == null) ? "" : "; expires=" + exdate.toUTCString()) +
((path == null) ? "; path=/" : "; path=" + path) +
((domain == null) ? "" : "; domain=" + domain) +
((secure == null) ? "" : "; secure");
if ( ! window.AdvancedAdsAdmin ) window.AdvancedAdsAdmin = {}
if ( ! window.AdvancedAdsAdmin.AdImporter ) window.AdvancedAdsAdmin.AdImporter = {
* will highlight the currently selected ads in the list
* @param hideInactive when true will hide inactive ad units
* @returns the selector of the selected row or false if no row was selected.
highlightSelectedRowInExternalAdsList: function ( hideInactive ) {
if ( typeof (hideInactive) == 'undefined' ) hideInactive = AdvancedAdsAdmin.AdImporter.adNetwork.hideIdle
const tbody = jQuery( '#mapi-table-wrap tbody' )
const btn = jQuery( '#mapi-toggle-idle' )
// count the ad units to determine if there's a need for the overflow class (scrolling)
const nbUnits = hideInactive
? jQuery( '#mapi-table-wrap tbody tr[data-active=1]' ).length
: jQuery( '#mapi-table-wrap tbody tr' ).length
if ( nbUnits > 8 ) jQuery( '#mapi-table-wrap' ).addClass( 'overflow' )
else jQuery( '#mapi-table-wrap' ).removeClass( 'overflow' )
const selectedRow = AdvancedAdsAdmin.AdImporter.getSelectedRow()
tbody.find( 'tr' ).removeClass( 'selected error' );
//make sure, it is visible before applying the zebra stripes
// make the table's rows striped.
const visible = tbody.find( 'tr:visible' )
visible.filter( ':odd' ).css( 'background-color', '#FFFFFF' )
visible.filter( ':even' ).css( 'background-color', '#F9F9F9' )
// highlight the selected row
// highlight the selected row
selectedRow.css( 'background-color', '' )
selectedRow.addClass( 'selected' )
this.scrollToSelectedRow(selectedRow);
return selectedRow || false
scrollToSelectedRow($selectedRow) {
const $wrap = jQuery('#mapi-table-wrap'),
wrapHeight = $wrap.height(),
wrapScrolled = $wrap.scrollTop();
// just in case this does not get passed a selected row, scroll to top of the table
$wrap.animate({scrollTop: 0}, 200);
// get the position of the selectedRow within the table wrap
let scroll = $selectedRow.position().top,
bottom = +scroll + $selectedRow.height();
// if the (top of the) element is not yet visible scroll to it
if (scroll < wrapScrolled || bottom > wrapScrolled || scroll > wrapScrolled + wrapHeight) {
// scrolled element is below current scroll position, i.e. we need to scroll past it not to top
if (bottom > $wrap.children('table').height() - wrapHeight) {
// if the selected element is on the "first page" let's scroll all the way to the top
if (scroll < wrapHeight) {
$wrap.animate({scrollTop: scroll}, 200);
const selectedId = AdvancedAdsAdmin.AdImporter.adNetwork.getSelectedId()