$_REQUEST['post_id'],
'post_type' => ANPIP_Meta_Box::$screens,
] );
if ( ! $query->have_posts() ) {
$response = 'Post is not found!';
} else {
$query->the_post();
echo '
';
}
}
die( $response );
}
add_action( 'wp_ajax_' . ANPIP_AJAX_ACTION, 'anpip_get_ajax_page' );
add_action( 'wp_ajax_nopriv_' . ANPIP_AJAX_ACTION, 'anpip_get_ajax_page' );
// ---------------------------------------------------------------------------------------------------------------------
// INIT AJAX ACTIONS (BEGIN)
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// INIT JS/CSS (BEGIN)
// ---------------------------------------------------------------------------------------------------------------------
function anpip_get_popup_pages() {
global $wpdb;
static $pages;
if ( null === $pages ) {
$meta_key = esc_sql( ANPIP_Meta_Box::$meta_key );
$results = $wpdb->get_results(
/** @lang sql */"SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = '{$meta_key}' and meta_value = 'y'",
ARRAY_A
);
$pages = [];
foreach ( $results as $row ) {
$lang = wpml_get_language_information( null, $row['post_id'] );
if ( $lang['language_code'] == ICL_LANGUAGE_CODE ) {
$post_id = apply_filters( 'wpml_object_id', $row['post_id'] );
if ( $post_id && ! array_key_exists( $post_id, $pages ) ) {
$pages[$post_id] = get_permalink( $post_id );
}
}
}
}
return $pages;
}
function anpip_enqueue_scripts() {
wp_enqueue_style( 'magnific_popup', plugins_url( 'css/magnific-popup.css', __FILE__ ) );
wp_enqueue_script( 'magnific_popup', plugins_url( 'js/jquery.magnific-popup.js', __FILE__ ), [ 'jquery' ] );
wp_enqueue_style( 'anpip_popup', plugins_url( 'css/popup.css', __FILE__ ) );
wp_enqueue_script( 'anpip_popup', plugins_url( 'js/popup.js', __FILE__ ), [ 'magnific_popup' ] );
wp_localize_script( 'anpip_popup', 'anpip_settings', [
'pages' => anpip_get_popup_pages(),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'ajax_action' => ANPIP_AJAX_ACTION,
] );
}
add_action( 'wp_enqueue_scripts', 'anpip_enqueue_scripts' );
// ---------------------------------------------------------------------------------------------------------------------
// INIT JS/CSS (END)
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// INTERNATIONALIZATION (BEGIN)
// ---------------------------------------------------------------------------------------------------------------------
function anpip_textdomain() {
$plugin_rel_path = basename( dirname( __FILE__ ) ) . '/languages/';
load_plugin_textdomain( ANPIP_TEXT_DOMAIN, false, $plugin_rel_path );
}
add_action( 'plugins_loaded', 'anpip_textdomain' );
// ---------------------------------------------------------------------------------------------------------------------
// INTERNATIONALIZATION (END)
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// METABOX (BEGIN)
// ---------------------------------------------------------------------------------------------------------------------
abstract class ANPIP_Meta_Box {
public static $meta_key = '_anpip_enabled';
public static $screens = [ 'post', 'page', /*'some_cpt',*/ ];
public static function add() {
global $screen;
foreach ( self::$screens as $screen ) {
add_meta_box(
'abpip_box_id', // Unique ID
__( 'Page In Popup', ANPIP_TEXT_DOMAIN ), // Box title
[ self::class, 'html' ], // Content callback, must be of type callable
$screen, // Post type,
'side' // Context
);
}
}
public static function save( $post_id ) {
$post_type = get_post_type( $post_id );
if ( ! in_array( $post_type, self::$screens ) ) return;
if ( ! isset( $_POST[self::$meta_key . '_nonce'] )
|| ! wp_verify_nonce( $_POST[self::$meta_key . '_nonce'], self::$meta_key ) ) {
return;
}
if ( array_key_exists( self::$meta_key, $_POST ) ) {
if ( is_plugin_active( 'divi-builder/divi-builder.php' ) && et_pb_is_pagebuilder_used( $post_id ) ) {
$meta_value = 'n';
} else {
$meta_value = ( @$_POST[ self::$meta_key ] == 'y' ) ? 'y' : 'n';
}
if ( 'y' == $meta_value ) {
update_post_meta( $post_id, self::$meta_key, $meta_value );
} else {
delete_post_meta( $post_id, self::$meta_key );
}
}
}
public static function html( $post ) {
$name = esc_attr( self::$meta_key );
if ( is_plugin_active( 'divi-builder/divi-builder.php' ) && et_pb_is_pagebuilder_used( $post->ID ) ) {
?>
ID, self::$meta_key, true );
?>