Meta Child Mosaik 1
class sqpp_metabox_child_mosaik {
public function __construct() {
if ( is_admin() ) {
add_action( 'load-post.php', array( $this, 'init_metabox' ) );
add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
}
}
public function init_metabox() {
add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) );
add_action( 'save_post', array( $this, 'save_metabox' ), 10, 2 );
}
public function add_metabox() {
add_meta_box(
'sqpp-mb-child-mosaik',
__( 'Child Pages Mosaik', 'sqppcptmeta' ),
array( $this, 'render_sqpp_mb_child_mosaik' ),
'page',
'advanced',
'core'
);
}
public function render_sqpp_mb_child_mosaik( $post ) {
// Add nonce for security and authentication.
wp_nonce_field( 'nonce_action', 'nonce' );
// Retrieve an existing value from the database.
$sqpp_mb_child_mosaik_select = get_post_meta( $post->ID, 'sqpp_mb_child_mosaik_select', true );
// Set default values.
if( empty( $sqpp_mb_child_mosaik_select ) ) $sqpp_mb_child_mosaik_select = '';
// Form fields.
echo '<table class="form-table">';
echo ' <tr>';
echo ' <th><label for="sqpp_mb_child_mosaik_select" class="sqpp_mb_child_mosaik_select_label">' . __( 'Select', 'sqppcptmeta' ) . '</label></th>';
echo ' <td>';
echo ' <label><input type="radio" name="sqpp_mb_child_mosaik_select" class="sqpp_mb_child_mosaik_select_field" value="1" ' . checked( $sqpp_mb_child_mosaik_select, '1', false ) . '> ' . __( 'No Mosaik – No Display of Child Pages', 'sqppcptmeta' ) . '</label><br>';
echo ' <label><input type="radio" name="sqpp_mb_child_mosaik_select" class="sqpp_mb_child_mosaik_select_field" value="2" ' . checked( $sqpp_mb_child_mosaik_select, '2', false ) . '> ' . __( 'Yes – Narrow Mosaik (3 Columns)', 'sqppcptmeta' ) . '</label><br>';
echo ' <label><input type="radio" name="sqpp_mb_child_mosaik_select" class="sqpp_mb_child_mosaik_select_field" value="3" ' . checked( $sqpp_mb_child_mosaik_select, '3', false ) . '> ' . __( 'Yes - Wide Mosaik (5 Columns)', 'sqppcptmeta' ) . '</label><br>';
echo ' <p class="description">' . __( 'Possibility to add the child pages of this page as a mosaik in a mansory style.', 'sqppcptmeta' ) . '</p>';
echo ' </td>';
echo ' </tr>';
echo '</table>';
}
public function save_metabox( $post_id, $post ) {
// Add nonce for security and authentication.
$nonce_name = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
$nonce_action = 'nonce_action';
// Check if a nonce is set.
if ( ! isset( $nonce_name ) )
return;
// Check if a nonce is valid.
if ( ! wp_verify_nonce( $nonce_name, $nonce_action ) )
return;
// Check if the user has permissions to save data.
if ( ! current_user_can( 'edit_post', $post_id ) )
return;
// Check if it's not an autosave.
if ( wp_is_post_autosave( $post_id ) )
return;
// Check if it's not a revision.
if ( wp_is_post_revision( $post_id ) )
return;
// Sanitize user input.
$new_sqpp_mb_child_mosaik_select = isset( $_POST[ 'sqpp_mb_child_mosaik_select' ] ) ? $_POST[ 'sqpp_mb_child_mosaik_select' ] : '';
// Update the meta field in the database.
update_post_meta( $post_id, 'sqpp_mb_child_mosaik_select', $new_sqpp_mb_child_mosaik_select );
}
}
new sqpp_metabox_child_mosaik;