* Author: Brian Stunnert * Version: 1.0 * * Copyright 2013 Brian Stunnert (email : brian.stunnert@outlook.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * @package Easy-Script-Adder * @author John Regan * @version 1.0 */ /** * Print direct link to Add Custom Scripts admin page * * Fetches array of links generated by WP Plugin admin page ( Deactivate | Edit ) * and inserts a link to the Add Custom Scripts admin page * * @since 1.0 * @param array $links Array of links generated by WP in Plugin Admin page. * @return array $links Array of links to be output on Plugin Admin page. */ function ssjr3_settings_link( $links ) { $settings_page = 'Settings'; array_unshift( $links, $settings_page ); return $links; } $plugin = plugin_basename(__FILE__); add_filter( "plugin_action_links_$plugin", 'ssjr3_settings_link' ); /** * Register text domain * * @since 1.0 */ function ssjr3_textdomain() { load_plugin_textdomain('ssjr3'); } add_action('init', 'ssjr3_textdomain'); /** * Delete Settings on Uninstall * * @since 1.0 */ function ssjr3_uninstall() { unregister_setting( 'ssjr3_settings_group', 'ssjr3_settings' ); } register_uninstall_hook( __FILE__, 'ssjr3_uninstall' ); /** * Print Header Scripts * * @since 1.0 */ function ssjr3_header_scripts() { ob_start(); $options = get_option( 'ssjr3_settings' ); $sfhs_header = isset( $options['header_scripts_input'] ) ? $options['header_scripts_input'] : ''; echo ""; echo ob_get_clean(); } /** * Print Footer Scripts * * @since 1.0 */ function ssjr3_footer_scripts() { ob_start(); $options = get_option( 'ssjr3_settings' ); $sfhs_footer = isset( $options['footer_scripts_input'] ) ? $options['footer_scripts_input'] : ''; echo ""; echo ob_get_clean(); } /** * Attaches Scripts to Hooks to be rendered * * @since 1.0 */ function ssjr3_render_scripts() { $options = get_option( 'ssjr3_settings' ); if ( isset( $options['header_scripts_input'] ) ) add_action( 'wp_head', 'ssjr3_header_scripts' ); if ( isset( $options['footer_scripts_input'] ) ) add_action( 'wp_footer', 'ssjr3_footer_scripts' ); } add_action( 'init', 'ssjr3_render_scripts' ); /** * Register "Header/Footer Scripts" submenu in "Tools" Admin Menu * * @since 1.0 */ function ssjr3_register_submenu_page() { add_management_page( __( 'Add Custom Scripts', 'ssjr3' ), __( 'Header/Footer Scripts', 'ssjr3' ), 'edit_themes', basename(__FILE__), 'ssjr3_render_submenu_page' ); } add_action( 'admin_menu', 'ssjr3_register_submenu_page' ); /** * Register settings * * @since 1.0 */ function ssjr3_register_settings() { register_setting( 'ssjr3_settings_group', 'ssjr3_settings' ); add_settings_section( 'ssjr3_primary_section', __( '', 'rt_polls' ), 'ssjr3_primary_section_cb', __FILE__ ); add_settings_field( 'ssjr3_header_scripts_input', __( 'Header Scripts', 'rt_polls' ), 'ssjr3_header_scripts_input', __FILE__, 'ssjr3_primary_section' ); add_settings_field( 'ssjr3_footer_scripts_input', __( 'Footer Scripts', 'rt_polls' ), 'ssjr3_footer_scripts_input', __FILE__, 'ssjr3_primary_section' ); add_settings_field( 'ssjr3_credit', __( 'This Plugin is Really Helpful!', 'rt_polls' ), 'ssjr3_credit', __FILE__, 'ssjr3_primary_section' ); } add_action('admin_init', 'ssjr3_register_settings'); /** * Render Primary Section text * * @since 1.0 */ function ssjr3_primary_section_cb() {} /** * Render Header Scripts Input * * @since 1.0 */ function ssjr3_header_scripts_input() { $options = get_option('ssjr3_settings'); $field_value = isset( $options['header_scripts_input'] ) ? $options['header_scripts_input'] : ''; ?> />