PluginProbe
LoftLoader / 2.3.2
LoftLoader v2.3.2
trunk 1.0.0 1.0.1 1.0.2 2.0.0 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3 2.3.1 2.3.2 2.3.3 All 34 releases
loftloader / inc / any-page / class-loftloader-any-page.php

class-loftloader-any-page.php in LoftLoader 2.3.2, at inc/any-page/class-loftloader-any-page.php

63 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! class_exists( 'LoftLoader_Any_Page' ) && !class_exists('LoftLoader_Any_Page_Filter')){
3 class LoftLoader_Any_Page{
4 public function __construct(){
5 add_action('add_meta_boxes', array($this, 'register_meta_boxes'));
6 add_action('save_post', array($this, 'save_meta'), 10, 3);
7
8 if ( ! is_admin() ) {
9 $this->alter_loftloader();
10 }
11
12 if ( function_exists( 'register_block_type' ) ) {
13 $this->load_gutenberg_panel();
14 }
15 }
16 // Load gutenberg file
17 protected function load_gutenberg_panel() {
18 require_once LOFTLOADER_ROOT . 'inc/any-page/gutenberg/class-gutenberg-any-page.php';
19 }
20 // Register loftloader shortcode meta box
21 public function register_meta_boxes(){
22 add_meta_box(
23 'loftloader_any_page_meta',
24 esc_html__( 'LoftLoader Any Page Shortcode', 'loftloader' ),
25 array( $this, 'metabox_callback' ),
26 'page',
27 'advanced',
28 'high',
29 array(
30 '__block_editor_compatible_meta_box' => true,
31 '__back_compat_meta_box' => true
32 )
33 );
34 }
35 // Show meta box html
36 public function metabox_callback( $post ) {
37 $shortcode = get_post_meta($post->ID, 'loftloader_page_shortcode', true); ?>
38 <textarea name="loftloader_page_shortcode" style="width: 100%;" rows="4"><?php echo esc_textarea( str_replace('/\\"/g', '\\\\"', $shortcode ) ); ?></textarea>
39 <input type="hidden" name="loftloader_any_page_nonce" value="<?php echo esc_attr( wp_create_nonce( 'loftloader_any_page_nonce' ) ); ?>" /> <?php
40 }
41 // Save loftloader shortcode meta
42 public function save_meta($post_id, $post, $update){
43 if ( empty( $update ) || ! in_array( $post->post_type, array( 'page' ) ) || empty( $_REQUEST['loftloader_any_page_nonce'] ) || ! empty( $_REQUEST['loftloader_gutenberg_enabled'] ) ) {
44 return $post_id;
45 }
46 if ( current_user_can( 'edit_post', $post_id ) ) {
47 $shortcode = '';
48 if ( ! empty( $_REQUEST['loftloader_page_shortcode'] ) ) {
49 $shortcode = sanitize_text_field( wp_unslash( $_REQUEST['loftloader_page_shortcode'] ) );
50 }
51 update_post_meta( $post_id, 'loftloader_page_shortcode', $shortcode );
52 }
53 return $_post_id;
54 }
55
56 // Initial LoftLoader Pro Shortcode actions
57 private function alter_loftloader() {
58 require_once LOFTLOADER_ROOT . 'inc/any-page/class-any-page-filter.php';
59 new LoftLoader_Any_Page_Filter();
60 }
61 }
62 new LoftLoader_Any_Page();
63 }