add_submenu_separator( $parent_slug, 5, 'members-eparator'); // 예시: 5번째 위치에 섹션 구분선 삽입
}
/**
* Ensure the ACF parent menu is selected for add-new.php
*
* @since 6.1
* @param string $parent_file The parent file checked against menu activation.
* @return string The modified parent file
*/
public function ensure_menu_selection( $parent_file ) {
if ( ! is_string( $parent_file ) ) {
return $parent_file;
}
if ( strpos( $parent_file, 'edit.php?post_type=amem-' ) === 0 ) {
return 'edit.php?post_type=acf-field-group';
}
return $parent_file;
}
function add_submenu_separator($parent_slug, $position, $menu_title) {
global $submenu;
// 배열의 특정 위치에 섹션 구분선을 삽입
$new_submenu_item = array('
', 'read', '#'.sanitize_title($menu_title), '', 'wp-menu-separator amem-submenu-separator-wrap');
// 해당 위치에 삽입
if(isset($submenu[$parent_slug])){
array_splice($submenu[$parent_slug], $position, 0, array($new_submenu_item));
}
}
/**
* Load the body class and scripts.
*
* @since 1.0.0
*/
public function admin_load() {
add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
add_action( 'admin_print_scripts', array( $this, 'admin_head' ) );
// acf_enqueue_scripts();
}
public function update_dashboard() {
if( !isset($_POST['dashboard_update_nonce']) || !wp_verify_nonce( sanitize_key($_POST['dashboard_update_nonce']), 'amem_dashboard_update' ) ){ // phpcs:disable WordPress.Security.NonceVerification -- already verified by ACF
return false;
}
if( isset($_POST['amem_modules'])){ // phpcs:disable WordPress.Security.NonceVerification -- already verified by ACF
$new_modules = amem_sanitize_vars( $_POST['amem_modules'] );
update_option( 'amem_modules', $new_modules ); // phpcs:disable WordPress.Security.NonceVerification -- already verified by ACF
amem()->options->modules = $new_modules; // phpcs:disable WordPress.Security.NonceVerification -- already verified by ACF
acf_add_admin_notice( __('Dashboard Update Success', 'advanced-members'), 'success' );
}
}
public function update_option() {
if( !isset($_POST['option_update_nonce']) || !wp_verify_nonce( sanitize_key($_POST['option_update_nonce']), 'amem_options_update' ) ) {
return false;
}
if( !empty($_POST['amem_options']) || !is_array($_POST['amem_options']) ) {
$new_options = $this->sanitize_options( $_POST['amem_options'] );
update_option( 'amem_options', $new_options );
do_action( 'amem/admin/update_options' );
acf_add_admin_notice( __('Options Update Success', 'advanced-members'), 'success' );
}
}
function sanitize_email_body($body) {
$wp_default_protocols = wp_allowed_protocols();
$protocols = array_merge( $wp_default_protocols, array( 'data' ) );
return wp_kses( stripslashes( $body ), 'post', $protocols );
}
function sanitize_options( $data, $sanitizers = null ) {
foreach( $data as $name => $option ) {
switch ($name) {
case 'accform':
case 'regform':
if( isset($option['rules']) ){
$i = 0;
foreach ($option['rules'] as $key => $value) {
$data[$name]['rules'][$i] = amem_sanitize_vars($value);
unset($data[$name]['rules'][$key]);
$i = $i + 1;
}
}
break;
case 'email':
foreach ($option as $key => $mail_option) {
if( isset($option[$key]['body'])) {
$data[$name][$key]['body'] = $this->sanitize_email_body($mail_option['body']);
}
}
break;
case 'avatar':
$sizes = trim( sanitize_text_field($data[$name]['avatar_sizes']) );
if ( $sizes ) {
$sizes = explode(',', $sizes );
$sizes = array_filter( array_map('intval', $sizes), function($v) {
return $v >= 80 && $v <= 512;
} );
sort($sizes);
$sizes = implode(',', $sizes );
}
if ( !$sizes ) {
$sizes = '96,150,300';
}
$data[$name]['avatar_sizes'] = $sizes;
break;
default:
$sanitizers = $sanitizers ? $sanitizers : amem()->options->sanitizers();
if ( isset($sanitizers[$name]) ) {
switch ( $sanitizers[$name] ) {
case 'int':
if ( is_array( $option ) ) {
$data[$name] = map_deep( $option, 'intval' );
} else {
$data[$name] = (int) $option;
}
break;
case 'absint':
if ( is_array( $option ) ) {
$data[$name] = map_deep( $option, 'absint' );
} else {
$data[$name] = absint( $option );
}
break;
case 'empty_absint':
if ( is_array( $option ) ) {
$data[$name] = map_deep( $option, 'absint' );
} else {
$data[$name] = ( '' !== $option ) ? absint( $option ) : '';
}
break;
case 'key':
if ( is_array( $option ) ) {
$data[$name] = map_deep( $option, 'sanitize_key' );
} else {
$data[$name] = sanitize_key( $option );
}
break;
case 'bool':
if ( is_array($option) ) {
$data[$name] = map_deep( $option, 'boolval' );
} else {
$data[$name] = (bool) $option;
}
break;
case 'url':
if ( is_array( $option ) ) {
$data[$name] = map_deep( $option, 'esc_url_raw' );
} else {
$data[$name] = esc_url_raw( $option );
}
break;
case 'wp_kses':
if ( is_array( $option ) ) {
$data[$name] = map_deep( $option, 'wp_kses_post' );
} else {
$data[$name] = wp_kses_post( $option );
}
break;
case 'textarea':
if ( is_array( $option ) ) {
$data[$name] = map_deep( $option, 'sanitize_textarea_field' );
} else {
$data[$name] = sanitize_textarea_field( $option );
}
break;
case 'text':
if ( is_array( $option ) ) {
$data[$name] = map_deep( $option, 'sanitize_text_field' );
} else {
$data[$name] = sanitize_text_field( $option );
}
break;
case 'array_text':
if ( $option )
$data[$name] = map_deep( $option, 'sanitize_text_field' );
else
$data[$name] = [];
break;
case 'email_body':
if ( is_array( $option ) ) {
$data[$name] = map_deep( $option, [$this, 'sanitize_email_body'] );
} else {
$data[$name] = $this->sanitize_email_body( $option );
}
break;
case is_array($sanitizers[$name]):
$data[$name] = $this->sanitize_options( $option, $sanitizers[$name] );
// foreach( $sanitizers[$name] as $skey => $sname ) {
// if ( isset($sanitizers[$skey]) && !is_array($sanitizers[$skey]) ) {
// $data[$name]
// }
// }
break;
default:
$data[$name] = apply_filters( 'amem/option/sanitize/method=' . $sanitizers[$name] , $option );
break;
}
} else {
$data[$name] = apply_filters( 'amem/option/sanitize/name=' . $name, $option );
}
break;
}
}
return $data;
}
/**
* Modifies the admin body class.
*
* @since 1.0.0
*
* @param string $classes Space-separated list of CSS classes.
* @return string
*/
public function admin_body_class( $classes ) {
$classes .= ' amem-admin-page amem-option-page acf-admin-page';
return $classes;
}
/**
* postbox_submitdiv
*
* This function will render the submitdiv metabox
*
* @type function
* @since 1.0.0
*
* @param n/a
* @return n/a
**/
function postbox_submitdiv( $post, $args ) {
/**
* Fires before the major-publishing-actions div.
*
* @since 1.0
*
* @param array $page The current options page.
*/
do_action( 'acf/options_page/submitbox_before_major_actions' );
?>
Need Help?
We have a knowledge
base full of articles to get
you started.
Browse Documentation
page['updated_message'], 'success' );
// }
// add submit div
// add_meta_box( 'submitdiv', __( 'Update Settings', 'advanced-members' ), array( $this, 'postbox_submitdiv' ), 'amem_options_page', 'side', 'high' );
// add_meta_box( 'submitdiv', __( 'Save', 'advanced-members' ), array( $this, 'postbox_submit_dashboard' ), 'amem_dashboard_page', 'side', 'high' );
// add_meta_box( 'dashdocu', __( 'Documentation', 'advanced-members' ), array( $this, 'postbox_dashboard_document' ), 'amem_dashboard_page', 'side', 'low' );
}
function amem_dashboard() {
/*
$page = ! empty( $_REQUEST['page'] ) ? sanitize_key( $_REQUEST['page'] ) : '';
if ( $page == 'amem_dashboard' ) { ?>