plugin_screen_hook_suffix ) return; wp_enqueue_script( 'media-upload' ); wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'wp-lists' ); wp_enqueue_script( 'seed_s404f-framework-js', SEED_S404F_PLUGIN_URL . 'framework/settings-scripts.js', array( 'jquery' ), $this->plugin_version ); wp_enqueue_script( 'theme-preview' ); wp_enqueue_style( 'thickbox' ); wp_enqueue_style( 'media-upload' ); wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_style( 'seed_s404f-framework-css', SEED_S404F_PLUGIN_URL . 'framework/settings-style.css', false, $this->plugin_version ); wp_enqueue_style( 'font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css', false, $this->plugin_version ); } /** * Creates WordPress Menu pages from an array in the config file. * * This function is attached to the admin_menu action hook. * * @since 0.1.0 */ function create_menus( ) { $this->plugin_screen_hook_suffix = add_options_page( __( "404 Page by SeedProd", 'seedprod' ), __( "404 Page by SeedProd", 'seedprod' ), 'manage_options', 'seed_s404f', array( &$this , 'option_page' ) ); } /** * Display settings link on plugin page */ function plugin_action_links( $links, $file ) { $plugin_file = SEED_S404F_SLUG; if ( $file == $plugin_file ) { $settings_link = 'Settings'; array_unshift( $links, $settings_link ); } return $links; } /** * Allow Tabs on the Settings Page * */ function plugin_options_tabs( ) { $menu_slug = null; $page = $_REQUEST[ 'page' ]; $uses_tabs = false; $current_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : false; //Check if this config uses tabs foreach ( seed_s404f_get_options() as $v ) { if ( $v[ 'type' ] == 'tab' ) { $uses_tabs = true; break; } } // If uses tabs then generate the tabs if ( $uses_tabs ) { echo ''; } } /** * Get the layout for the page. classic|2-col * */ function get_page_layout( ) { $layout = 'classic'; foreach ( seed_s404f_get_options() as $v ) { switch ( $v[ 'type' ] ) { case 'menu'; $page = $_REQUEST[ 'page' ]; if ( $page == $v[ 'menu_slug' ] ) { if ( isset( $v[ 'layout' ] ) ) { $layout = $v[ 'layout' ]; } } break; } } return $layout; } /** * Render the option pages. * * @since 0.1.0 */ function option_page( ) { $menu_slug = null; $page = $_REQUEST[ 'page' ]; $layout = $this->get_page_layout(); ?>

plugin_name; ?>

plugin_options_tabs(); ?>
$_GET['tab'])); ?>
'; $this->do_settings_sections( $v[ 'id' ],$show_submit ); echo '
'; } else { do_settings_sections( $v[ 'id' ] ); } } break; } } } ?>

$v ) { switch ( $v[ 'type' ] ) { case 'menu': $menu_slug = $v[ 'menu_slug' ]; break; case 'setting': if ( empty( $v[ 'validate_function' ] ) ) { $v[ 'validate_function' ] = array( &$this, 'validate_machine' ); } register_setting( $v[ 'id' ], $v[ 'id' ], $v[ 'validate_function' ] ); $setting_id = $v[ 'id' ]; break; case 'section': if ( empty( $v[ 'desc_callback' ] ) ) { $v[ 'desc_callback' ] = array( &$this, '__return_empty_string' ); } else { $v[ 'desc_callback' ] = $v[ 'desc_callback' ]; } add_settings_section( $v[ 'id' ], $v[ 'label' ], $v[ 'desc_callback' ], $v[ 'id' ] ); $section_id = $v[ 'id' ]; break; case 'tab': break; default: if ( empty( $v[ 'callback' ] ) ) { $v[ 'callback' ] = array( &$this, 'field_machine' ); } add_settings_field( $v[ 'id' ], $v[ 'label' ], $v[ 'callback' ], $section_id, $section_id, array( 'id' => $v[ 'id' ], 'desc' => ( isset( $v[ 'desc' ] ) ? $v[ 'desc' ] : '' ), 'setting_id' => $setting_id, 'class' => ( isset( $v[ 'class' ] ) ? $v[ 'class' ] : '' ), 'type' => $v[ 'type' ], 'default_value' => ( isset( $v[ 'default_value' ] ) ? $v[ 'default_value' ] : '' ), 'option_values' => ( isset( $v[ 'option_values' ] ) ? $v[ 'option_values' ] : '' ) ) ); } } } /** * Create a field based on the field type passed in. * * @since 0.1.0 */ function field_machine( $args ) { extract( $args ); //$id, $desc, $setting_id, $class, $type, $default_value, $option_values // Load defaults $defaults = array( ); foreach ( seed_s404f_get_options() as $k ) { switch ( $k[ 'type' ] ) { case 'setting': case 'section': case 'tab': break; default: if ( isset( $k[ 'default_value' ] ) ) { $defaults[ $k[ 'id' ] ] = $k[ 'default_value' ]; } } } $options = get_option( $setting_id ); $options = wp_parse_args( $options, $defaults ); $path = SEED_S404F_PLUGIN_PATH . 'framework/field-types/' . $type . '.php'; if ( file_exists( $path ) ) { // Show Field include( $path ); // Show description if ( !empty( $desc ) ) { echo "{$desc}"; } } } /** * Validates user input before we save it via the Options API. If error add_setting_error * * @since 0.1.0 * @param array $input Contains all the values submitted to the POST. * @return array $input Contains sanitized values. * @todo Figure out best way to validate values. */ function validate_machine( $input ) { $option_page = $_POST['option_page']; foreach ( seed_s404f_get_options() as $k ) { switch ( $k[ 'type' ] ) { case 'menu': case 'setting': if(isset($k['id'])) $setting_id = $k['id']; case 'section': case 'tab'; break; default: if ( !empty( $k[ 'validate' ] ) && $setting_id == $option_page ) { $validation_rules = explode( ',', $k[ 'validate' ] ); foreach ( $validation_rules as $v ) { $path = SEED_S404F_PLUGIN_PATH . 'framework/validations/' . $v . '.php'; if ( file_exists( $path ) ) { // Defaults Values $is_valid = true; $error_msg = ''; // Test Validation include( $path ); // Is it valid? if ( $is_valid === false ) { add_settings_error( $k[ 'id' ], 'seedprod_error', $error_msg, 'error' ); // Unset invalids unset( $input[ $k[ 'id' ] ] ); } } } //end foreach } } } return $input; } /** * Dummy function to be called by all sections from the Settings API. Define a custom function in the config. * * @since 0.1.0 * @return string Empty */ function __return_empty_string( ) { echo ''; } /** * SeedProd version of WP's do_settings_sections * * @since 0.1.0 */ function do_settings_sections( $page, $show_submit ) { global $wp_settings_sections, $wp_settings_fields; if ( !isset( $wp_settings_sections ) || !isset( $wp_settings_sections[ $page ] ) ) return; foreach ( (array) $wp_settings_sections[ $page ] as $section ) { echo "

{$section['title']}

\n"; echo '
'; call_user_func( $section[ 'callback' ], $section ); if ( !isset( $wp_settings_fields ) || !isset( $wp_settings_fields[ $page ] ) || !isset( $wp_settings_fields[ $page ][ $section[ 'id' ] ] ) ) continue; echo ''; $this->do_settings_fields( $page, $section[ 'id' ] ); echo '
'; if($show_submit): ?>

'; } } function do_settings_fields($page, $section) { global $wp_settings_fields; if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) ) return; foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { echo ''; if ( !empty($field['args']['label_for']) ) echo ''; else echo '' . $field['title'] . ''; echo ''; call_user_func($field['callback'], $field['args']); echo ''; echo ''; } } }