| 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 |
} |