' . "\n"; // JSON-encoded list of scripts and styles to be handled differently from default // decode then encode as a way to escpae the contents since JSON is JS-safe echo "var asset_finder_handles = " . json_encode( json_decode( $options ) ) . ";"; // store in JS and use after assets loaded by create_admin_script() echo ''; } function sanitize_settings($input) { $output = array( 'scripts' => array(), 'styles' => array() ); // $newinput['scripts'] = trim($input['scripts']); foreach( $input['scripts'] as $handle => $action ) { $action = intval( $action ); if ( 0 < $action ) { $output['scripts'][ $handle ] = $action; } } foreach( $input['styles'] as $handle => $action ) { $action = intval( $action ); if ( 0 < $action ) { $output['styles'][ $handle ] = $action; } } return json_encode( $output ); } function settings_page() { echo '
'; echo '

' . esc_html( $this->title ) . '

'; echo '
'; settings_fields('asset_finder'); do_settings_sections('asset_finder_settings'); echo '

Scripts

'; echo '
HandleActionSource
'; echo '

Styles

'; echo '
HandleActionSource
'; $url = $this->get_settings_web_url( '' ); $this->create_admin_script( $url ); submit_button(); echo '
'; } function section_text() { echo '

You may choose to late-load or remove each script and stylesheet below.

'; } /** * Create the admin menus required by the plugin * */ function admin_menu() { add_options_page('Asset Finder', 'Asset Finder', 'manage_options', 'asset_finder_settings', array( $this, 'settings_page' ) ); } /** * Communicate between iframe and parent * Modifed from Petar Bojinov: https://gist.github.com/pbojinov/8965299 * */ private function create_admin_script( $url ) { echo ""; } /** * Return a timestamp 5 minutes in the future for admin to communicate request to web safel * */ private function get_settings_timestamp() { return current_time( 'timestamp' ) + ( 5 * 60 ); // now + 5 minutes } /** * Return the web URL to be tested for scripts and styles * */ private function get_settings_web_url( $path ) { return site_url() . '/' . $path . '?afts=' . $this->get_settings_timestamp(); } /** * Enqueue scripts and styles selectively bsed on admin screen * */ function admin_enqueue_scripts() { $screen = get_current_screen(); if ( 'settings_page_asset_finder_settings' === $screen->id ) { wp_enqueue_style( 'asset_finder_style', ASSET_FINDER_URI . 'css/admin.css', array(), 'v.1.0.0', 'screen' ); wp_enqueue_script( 'asset_finder_script', ASSET_FINDER_URI . 'js/admin.js', array(), 'v.1.0.2', true ); } } }