Astra_Ext_Advanced_Hooks_Meta::save_meta_box( number $post_id )
Metabox Save
Description
Parameters
- $post_id
-
(number) (Required) Post ID.
Return
(void)
Source
File: addons/advanced-hooks/classes/class-astra-ext-advanced-hooks-meta.php
public function save_meta_box( $post_id ) {
// Checks save status.
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ ASTRA_ADVANCED_HOOKS_POST_TYPE ] ) && wp_verify_nonce( $_POST[ ASTRA_ADVANCED_HOOKS_POST_TYPE ], basename( __FILE__ ) ) ) ? true : false;
// Exits script depending on save status.
if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
return;
}
$editor_type = get_post_meta( $post_id, 'editor_type', true );
if ( isset( $_GET['wordpress_editor'] ) || 'wordpress_editor' == $editor_type ) {
update_post_meta( $post_id, 'editor_type', 'wordpress_editor' );
} elseif ( isset( $_GET['code_editor'] ) || 'code_editor' == $editor_type ) {
update_post_meta( $post_id, 'editor_type', 'code_editor' );
} else {
update_post_meta( $post_id, 'editor_type', 'wordpress_editor' );
}
/**
* Get meta options
*/
$post_meta = self::get_meta_option();
foreach ( $post_meta as $key => $data ) {
if ( in_array( $key, array( 'ast-advanced-hook-users', 'ast-advanced-hook-padding' ) ) ) {
$index = array_search( '', $_POST[ $key ] );
if ( false !== $index ) {
unset( $_POST[ $key ][ $index ] );
}
$meta_value = array_map( 'esc_attr', $_POST[ $key ] );
} elseif ( in_array( $key, array( 'ast-advanced-time-duration', 'ast-advanced-display-device', 'ast-advanced-hook-header', 'ast-advanced-hook-footer', 'ast-404-page', 'ast-advanced-hook-content' ) ) ) {
$meta_value = isset( $_POST[ $key ] ) ? array_map( 'esc_attr', $_POST[ $key ] ) : array();
} elseif ( in_array( $key, array( 'ast-advanced-hook-location', 'ast-advanced-hook-exclusion' ) ) ) {
$meta_value = Astra_Target_Rules_Fields::get_format_rule_value( $_POST, $key );
} else {
// Sanitize values.
$sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_DEFAULT';
switch ( $sanitize_filter ) {
case 'FILTER_SANITIZE_STRING':
$meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING );
break;
case 'FILTER_SANITIZE_URL':
$meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL );
break;
case 'FILTER_SANITIZE_NUMBER_INT':
$meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT );
break;
default:
$meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
break;
}
}
// Store values.
if ( '' != $meta_value ) {
update_post_meta( $post_id, $key, $meta_value );
} else {
if ( 'ast-advanced-hook-php-code' !== $key ) {
delete_post_meta( $post_id, $key );
}
}
}
// Correct the target rules for 404-page layout.
$this->target_rules_404_layout();
}
Expand full source code Collapse full source code View on Trac