adminpages = apply_filters( 'plugin_admin_pages', $this->adminpages ); add_action( 'admin_print_scripts', array( $this, 'config_page_scripts' ) ); add_action( 'admin_print_styles', array( $this, 'config_page_styles' ) ); } /** * Generates the header for admin pages * * @param bool $form Whether or not the form should be included. * @param string $option The long name of the option to use for the current page. * @param string $optionshort The short name of the option to use for the current page. * @param bool $contains_files Whether the form should allow for file uploads. */ function admin_header( $form = true, $option = 'plugin_options', $optionshort = 'wpplugin', $contains_files = false ) { ?>

'; settings_fields( $option ); $this->currentoption = $optionshort; } } /** * Generates the footer for admin pages * * @param bool $submit Whether or not a submit button should be shown. */ function admin_footer( $submit = true ) { if ( $submit ) { submit_button(); } ?>
admin_sidebar(); ?>
adminpages ) ) { wp_enqueue_style( 'dashboard' ); wp_enqueue_style( 'thickbox' ); wp_enqueue_style( 'global' ); wp_enqueue_style( 'wp-admin' ); wp_enqueue_style( 'plugin-admin', plugins_url( 'css/plugin-admin.css', dirname( __FILE__ ) ), array(), al_VERSION ); //if ( is_rtl() ) //wp_enqueue_style( 'wpplugin-rtl', plugins_url( 'css/wpplugin-rtl.css', dirname( __FILE__ ) ), array(), al_VERSION ); } } /** * Loads the required scripts for the config page. */ function config_page_scripts() { global $pagenow; if ( $pagenow == 'tools.php' && isset( $_GET['page'] ) && in_array( $_GET['page'], $this->adminpages ) ) { //wp_enqueue_script( 'wpplugin-admin-script', plugins_url( 'js/plugin-admin.js', dirname( __FILE__ ) ), array( 'jquery' ), al_VERSION, true ); wp_enqueue_script( 'postbox' ); wp_enqueue_script( 'dashboard' ); wp_enqueue_script( 'thickbox' ); } } /** * Retrieve options based on the option or the class currentoption. * * @since 1.2.4 * * @param string $option The option to retrieve. * @return array */ function get_option( $option ) { if ( function_exists( 'is_network_admin' ) && is_network_admin() ) return get_site_option( $option ); else return get_option( $option ); } /** * Create a Checkbox input field. * * @param string $var The variable within the option to create the checkbox for. * @param string $label The label to show for the variable. * @param bool $label_left Whether the label should be left (true) or right (false). * @param string $option The option the variable belongs to. * @return string */ function checkbox( $var, $label, $label_left = false, $option = '' ) { if ( empty( $option ) ) { $option = $this->currentoption; } $options = $this->get_option( $option ); if ( ! isset( $options[$var] ) ) { $options[$var] = false; } if ( $options[$var] === true ) { $options[$var] = 'on'; } if ( $label_left !== false ) { if ( ! empty( $label_left ) ) { $label_left .= ':'; } $output_label = ''; $class = 'checkbox'; } else { $output_label = ''; $class = 'checkbox double'; } $output_input = ''; if ( $label_left !== false ) { $output = $output_label . $output_input . ''; } else { $output = $output_input . $output_label; } return $output . '
'; } /** * Create a Text input field. * * @param string $var The variable within the option to create the text input field for. * @param string $label The label to show for the variable. * @param string $option The option the variable belongs to. * @return string */ function textinput( $var, $label, $option = '' ) { if ( empty( $option ) ) { $option = $this->currentoption; } $options = $this->get_option( $option ); $val = ( isset( $options[$var] ) ) ? $options[$var] : ''; return '' . '
'; } /** * Create a textarea. * * @param string $var The variable within the option to create the textarea for. * @param string $label The label to show for the variable. * @param string $option The option the variable belongs to. * @param string $class The CSS class to assign to the textarea. * @return string */ function textarea( $var, $label, $option = '', $class = '' ) { if ( empty( $option ) ) { $option = $this->currentoption; } $options = $this->get_option( $option ); $val = ( isset( $options[$var] ) ) ? $options[$var] : ''; return '' . '
'; } /** * Create a hidden input field. * * @param string $var The variable within the option to create the hidden input for. * @param string $option The option the variable belongs to. * @return string */ function hidden( $var, $option = '' ) { if ( empty( $option ) ) { $option = $this->currentoption; } $options = $this->get_option( $option ); $val = ( isset( $options[$var] ) ) ? $options[$var] : ''; if ( is_bool( $val ) ) { $val = ( $val === true ) ? 'true' : 'false'; } return ''; } /** * Create a Select Box. * * @param string $var The variable within the option to create the select for. * @param string $label The label to show for the variable. * @param array $values The select options to choose from. * @param string $option The option the variable belongs to. * @return string */ function select( $var, $label, $values, $option = '' ) { if ( ! is_array( $values ) || $values === array() ) { return ''; } if ( empty( $option ) ) { $option = $this->currentoption; } $options = $this->get_option( $option ); $output = ''; $output .= ''; return $output . '
'; } /** * Create a File upload field. * * @param string $var The variable within the option to create the file upload field for. * @param string $label The label to show for the variable. * @param string $option The option the variable belongs to. * @return string */ function file_upload( $var, $label, $option = '' ) { if ( empty( $option ) ) { $option = $this->currentoption; } $options = $this->get_option( $option ); $val = ''; if ( isset( $options[$var] ) && is_array( $options[$var] ) ) { $val = $options[$var]['url']; } $var_esc = esc_attr( $var ); $output = ''; $output .= ''; // Need to save separate array items in hidden inputs, because empty file inputs type will be deleted by settings API. if ( ! empty( $options[$var] ) ) { $output .= ''; $output .= ''; $output .= ''; } $output .= '
'; return $output; } /** * Create a Radio input field. * * @param string $var The variable within the option to create the file upload field for. * @param array $values The radio options to choose from. * @param string $label The label to show for the variable. * @param string $option The option the variable belongs to. * @return string */ function radio( $var, $values, $label, $option = '' ) { if ( ! is_array( $values ) || $values === array() ) { return ''; } if ( empty( $option ) ) { $option = $this->currentoption; } $options = $this->get_option( $option ); if ( ! isset( $options[$var] ) ) { $options[$var] = false; } $var_esc = esc_attr( $var ); $output = '
'; foreach ( $values as $key => $value ) { $key_esc = esc_attr( $key ); $output .= ' '; } $output .= '
'; return $output; } /** * Create a postbox widget. * * @param string $id ID of the postbox. * @param string $title Title of the postbox. * @param string $content Content of the postbox. */ function postbox( $id, $title, $content ) { ?>

'; foreach ( $rows as $row ) { $content .= ''; if ( isset( $row['id'] ) && $row['id'] != '' ) $content .= ''; else $content .= esc_html( $row['label'] ); if ( isset( $row['desc'] ) && $row['desc'] != '' ) $content .= '
' . esc_html( $row['desc'] ) . ''; $content .= ''; $content .= $row['content']; $content .= ''; } $content .= ''; return $content; } } global $plugin_admin; $plugin_admin = new plugin_admin(); } ?>