PluginProbe
Wp-Insert / trunk
Wp-Insert vtrunk
trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.3.0 1.3.1 1.3.3 1.4 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 2.0 All 63 releases
wp-insert / includes / modules / core / gutenberg / module.php

module.php in Wp-Insert trunk, at includes/modules/core/gutenberg/module.php

74 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 add_action( 'init', 'wp_insert_gutenberg_block_init' );
3 function wp_insert_gutenberg_block_init() {
4 if ( function_exists( 'register_block_type' ) ) {
5 wp_register_script( 'wp_insert_gutenberg', WP_INSERT_URL . 'includes/modules/core/gutenberg/js/gutenberg.js', [ 'wp-blocks', 'wp-editor', 'wp-element' ], WP_INSERT_VERSION . wp_rand( 0, 9999 ), true );
6 register_block_type( 'wp-insert/wp-insert-gutenberg', [ 'editor_script' => 'wp_insert_gutenberg' ] );
7 }
8 }
9
10 add_action( 'admin_footer-post-new.php', 'wp_insert_gutenberg_admin_footer' );
11 add_action( 'admin_footer-post.php', 'wp_insert_gutenberg_admin_footer' );
12 function wp_insert_gutenberg_admin_footer() {
13 echo '<input type="hidden" id="wp_insert_gutenberg_admin_ajax" name="wp_insert_admin_ajax" value="' . esc_url( admin_url( 'admin-ajax.php' ) ) . '" />';
14 echo '<input type="hidden" id="wp_insert_gutenberg_nonce" name="wp_insert_nonce" value="' . esc_attr( wp_create_nonce( 'wp-insert-gutenberg' ) ) . '" />';
15 }
16
17 add_action( 'wp_ajax_wp_insert_gutenberg_get_ad_data', 'wp_insert_gutenberg_get_ad_data' );
18 function wp_insert_gutenberg_get_ad_data() {
19 check_ajax_referer( 'wp-insert-gutenberg', 'wp_insert_gutenberg_nonce' );
20 $adData = [];
21 $inpostads = get_option( 'wp_insert_inpostads' );
22 if ( isset( $inpostads ) && is_array( $inpostads ) ) {
23 foreach ( $inpostads as $key => $inpostad ) {
24 /* Begin Workaround for migrating old users to new system (can be removed in a later version) */
25 $title = $key;
26 if ( ! isset( $inpostad['title'] ) || ( $inpostad['title'] == '' ) ) {
27 switch ( $key ) {
28 case 'above':
29 $title = 'Above Post Content';
30 break;
31 case 'middle':
32 $title = 'Middle of Post Content';
33 break;
34 case 'below':
35 $title = 'Below Post Content';
36 break;
37 case 'left':
38 $title = 'To the Left of Post Content';
39 break;
40 case 'right':
41 $title = 'To the Right of Post Content';
42 break;
43 }
44 } else {
45 $title = $inpostad['title'];
46 }
47 /* End Workaround for migrating old users to new system (can be removed in a later version) */
48 $adData[] = [
49 'type' => 'inpostads',
50 'id' => $key,
51 'title' => 'In-Post Ad : ' . $title,
52 ];
53 }
54 }
55
56 $shortcodeads = get_option( 'wp_insert_shortcodeads' );
57 if ( isset( $shortcodeads ) && is_array( $shortcodeads ) ) {
58 foreach ( $shortcodeads as $key => $shortcodead ) {
59 $title = $key;
60 if ( isset( $shortcodead['title'] ) && ( $shortcodead['title'] != '' ) ) {
61 $title = $shortcodead['title'];
62 }
63 $adData[] = [
64 'type' => 'shortcodeads',
65 'id' => $key,
66 'title' => 'Shortcode Ad : ' . $title,
67 ];
68 }
69 }
70 echo '###SUCCESS###';
71 echo wp_json_encode( $adData );
72 wp_die();
73 }
74