__( 'Undefined', 'beans' ), 'context' => 'normal' ); $this->section = $section; $this->args = array_merge( $defaults, $args ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); $this->register_metabox(); } /** * Enqueue assets. */ public function enqueue_assets() { wp_enqueue_script( 'postbox' ); } /** * Register the Metabox. */ private function register_metabox() { add_meta_box( $this->section, $this->args['title'], array( $this, 'metabox_content' ), beans_get( 'page' ), $this->args['context'], 'default' ); } /** * Metabox content. */ public function metabox_content() { foreach ( beans_get_fields( 'option', $this->section ) as $field ) beans_field( $field ); } /** * Page content. */ public function page( $page ) { global $wp_meta_boxes; if ( !$boxes = beans_get( $page, $wp_meta_boxes ) ) return; // Only add column class if there is more than 1 metaboxes. $column_class = beans_get( 'column', $boxes, array() ) ? ' column' : false; // Set page data which will be used by the postbox. echo '
'; } /** * Form actions. */ public function actions() { if ( beans_post( 'beans_save_options' ) ) { $this->save(); add_action( 'admin_notices', array( $this, 'save_notices' ) ); } if ( beans_post( 'beans_reset_options' ) ) { $this->reset(); add_action( 'admin_notices', array( $this, 'reset_notices' ) ); } } /** * Save options. */ private function save() { if ( !wp_verify_nonce( beans_post( 'beans_options_nonce' ), 'beans_options_nonce' ) ) return false; if ( !( $fields = beans_post( 'beans_fields' ) ) ) return false; foreach ( $fields as $field => $value ) update_option( $field, stripslashes_deep( $value ) ); $this->success = true; } /** * Reset options. */ private function reset() { if ( !wp_verify_nonce( beans_post( 'beans_options_nonce' ), 'beans_options_nonce' ) ) return false; if ( !( $fields = beans_post( 'beans_fields' ) ) ) return false; foreach ( $fields as $field => $value ) delete_option( $field ); $this->success = true; } /** * Save notice content. */ public function save_notices() { if ( $this->success ) echo '' . __( 'Settings saved successfully!', 'beans' ) . '
' . __( 'Settings could not be saved, please try again.', 'beans' ) . '
' . __( 'Settings reset successfully!', 'beans' ) . '
' . __( 'Settings could not be reset, please try again.', 'beans' ) . '