';
$data = get_option( 'wp_insert_' . $type );
if ( isset( $data ) && is_array( $data ) ) {
foreach ( $data as $key => $value ) {
/* Begin Workaround for migrating old users to new system (can be removed in a later version) */
$title = $key;
if ( ! isset( $value['title'] ) || ( $value['title'] == '' ) ) {
switch ( $key ) {
case 'above':
$title = 'Above Post Content';
break;
case 'middle':
$title = 'Middle of Post Content';
break;
case 'below':
$title = 'Below Post Content';
break;
case 'left':
$title = 'To the Left of Post Content';
break;
case 'right':
$title = 'To the Right of Post Content';
break;
}
} else {
$title = $value['title'];
}
$title = sanitize_text_field( $title );
/* End Workaround for migrating old users to new system (can be removed in a later version) */
// Titles and keys are interpolated into inline JS handler arguments,
// so they are escaped for a JS string context, not just for HTML.
$jsTitle = esc_js( $title );
$jsKey = esc_js( $key );
$jsType = esc_js( $type );
echo '
';
echo '' . esc_html( $preTitle . ' : ' . $title ) . '';
echo '';
echo '';
echo '
';
}
}
echo '
Add New
';
echo '
';
echo '';
}
/* End Get Admin Panel Card*/
/* Begin Get Ad Form */
function wp_insert_get_ad_form( $script = '' ) {
check_ajax_referer( 'wp-insert', 'wp_insert_nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( -1, 403 );
}
if ( isset( $_POST['wp_insert_identifier'] ) && isset( $_POST['wp_insert_type'] ) ) {
$type = sanitize_key( wp_unslash( $_POST['wp_insert_type'] ) );
if ( ! in_array( $type, wp_insert_get_ad_unit_types(), true ) ) {
wp_die( -1, 400 );
}
$requestIdentifier = sanitize_text_field( wp_unslash( $_POST['wp_insert_identifier'] ) );
$data = get_option( 'wp_insert_' . $type );
$identifier = substr( str_shuffle( str_repeat( 'abcdefghijklmnopqrstuvwxyz', 5 ) ), 0, 5 ) . uniqid();
$dataIdentifier = $identifier;
if ( strpos( $requestIdentifier, '###DUPLICATE###' ) !== false ) {
$dataIdentifier = sanitize_key( str_replace( '###DUPLICATE###', '', $requestIdentifier ) );
if ( isset( $data[ $dataIdentifier ] ) ) {
$data[ $dataIdentifier ]['title'] = ( $data[ $dataIdentifier ]['title'] ?? '' ) . ' (Duplicate)';
}
} elseif ( $requestIdentifier != 'new' ) {
$identifier = sanitize_key( $requestIdentifier );
$dataIdentifier = $identifier;
}
echo '';
}
wp_die();
}
/* End Get Ad Form */
/* Begin Save Ad Data */
function wp_insert_save_ad_data() {
check_ajax_referer( 'wp-insert', 'wp_insert_nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( -1, 403 );
}
$type = ( isset( $_POST['wp_insert_type'] ) ? sanitize_key( wp_unslash( $_POST['wp_insert_type'] ) ) : '' );
$identifier = ( isset( $_POST['wp_insert_identifier'] ) ? sanitize_key( wp_unslash( $_POST['wp_insert_identifier'] ) ) : '' );
if ( ( $identifier != '' ) && in_array( $type, wp_insert_get_ad_unit_types(), true ) && ( isset( $_POST['wp_insert_parameters'] ) && is_array( $_POST['wp_insert_parameters'] ) ) ) {
$parameters = array_map( 'sanitize_key', wp_unslash( $_POST['wp_insert_parameters'] ) );
$data = get_option( 'wp_insert_' . $type );
if ( ! is_array( $data ) ) {
$data = [];
}
foreach ( $parameters as $parameter ) {
$field = str_replace( [ 'wp_insert_', $type . '_', $identifier . '_' ], '', $parameter );
// Ad code must reach the option table unmodified for unfiltered_html
// users; wp_insert_sanitize_ad_field() handles the per-field rules.
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$data[ $identifier ][ $field ] = wp_insert_sanitize_ad_field( $field, ( ( isset( $_POST[ $parameter ] ) ) ? $_POST[ $parameter ] : '' ) );
}
update_option( 'wp_insert_' . $type, $data );
if ( function_exists( 'wp_insert_adstxt_adsense_admin_notice_reset' ) ) {
wp_insert_adstxt_adsense_admin_notice_reset();
}
}
wp_die();
}
/* End Save Ad Data */
/* Begin Delete Ad Data */
function wp_insert_delete_ad_data() {
check_ajax_referer( 'wp-insert', 'wp_insert_nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( -1, 403 );
}
$type = ( isset( $_POST['wp_insert_type'] ) ? sanitize_key( wp_unslash( $_POST['wp_insert_type'] ) ) : '' );
$identifier = ( isset( $_POST['wp_insert_identifier'] ) ? sanitize_key( wp_unslash( $_POST['wp_insert_identifier'] ) ) : '' );
if ( ( $identifier != '' ) && in_array( $type, wp_insert_get_ad_unit_types(), true ) ) {
$data = get_option( 'wp_insert_' . $type );
unset( $data[ $identifier ] );
update_option( 'wp_insert_' . $type, $data );
if ( function_exists( 'wp_insert_adstxt_adsense_admin_notice_reset' ) ) {
wp_insert_adstxt_adsense_admin_notice_reset();
}
}
wp_die();
}
/* End Delete Ad Data */