__( 'Editor & Content', 'wp-coder' ),
'admin' => __( 'Admin Interface Tweaks', 'wp-coder' ),
'login' => __( 'Login & User Access', 'wp-coder' ),
'media' => __( 'Media & Embeds', 'wp-coder' ),
'core' => __( 'Core Functionality', 'wp-coder' ),
'comments' => __( 'Comments & Feedback', 'wp-coder' ),
'optimization' => __( ' Cleanup & Optimization', 'wp-coder' ),
];
?>
';
$i = 1;
foreach ( $settings as $name => $args ) {
$checked = array_key_exists( $name, $options ) ? 'checked' : ''; ?>
';
}
private static function field( $type = 'checkbox', $name = '', $def = '', $placeholder = '' ) {
$options = get_option( '_wp_coder_snippets', [] );
if ( $type === 'checkbox' ) {
$checked = array_key_exists( $name, $options ) ? 'checked' : '';
echo '';
echo '';
} elseif ( $type === 'text' ) {
$value = ! empty( $options[ $name ] ) ? $options[ $name ] : $def;
echo '';
} elseif ( $type === 'textarea' ) {
$value = ! empty( $options[ $name ] ) ? $options[ $name ] : $def;
echo '';
} elseif ( $type === 'number' ) {
$value = ! empty( $options[ $name ] ) ? $options[ $name ] : $def;
echo '';
}
}
private static function send(): void {
if ( ! self::verify() ) {
return;
}
if ( empty( $_POST['wp_coder_snippet'] ) ) {
$snippets = [];
} else {
$snippets = map_deep( wp_unslash( $_POST['wp_coder_snippet'] ), 'sanitize_text_field' );
}
update_option( '_wp_coder_snippets', $snippets );
}
private static function verify(): bool {
$wp_coder = $_POST['wp_coder_snippet'] ?? '';
$nonce_name = WPCoder::PREFIX . '_save_snippet';
$nonce_action = WPCoder::PREFIX . '_snippets_action';
if ( empty( $_POST[ $nonce_name ] ) ) {
return false;
}
return isset( $_POST['wp_coder_snippet'] ) && wp_verify_nonce( $_POST[ $nonce_name ],
$nonce_action ) && current_user_can( 'unfiltered_html' );
}
}