Created
November 20, 2012 20:41
-
-
Save kurtpayne/4120936 to your computer and use it in GitHub Desktop.
Customize P3's Auto Scan URLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: P3 Custom Scanner | |
Plugin URI: http://inside.godaddy.com/ | |
Description: Customize the pages scanned by P3's auto scan mode | |
Author: GoDaddy.com | |
Version: 1.0 | |
Author URI: http://www.godaddy.com/ | |
*/ | |
$p3_customizer = new P3_Customizer_Plugin(); | |
register_activation_hook( __FILE__, array( 'P3_Customizer_Plugin', 'activate' ) ); | |
register_uninstall_hook( __FILE__, array( 'P3_Customizer_Plugin', 'uninstall' ) ); | |
class P3_Customizer_Plugin { | |
public function __construct() { | |
add_action( 'admin_init', array( $this, 'register_settings' ) ); | |
add_action( 'admin_menu', array( $this, 'settings_page' ) ); | |
add_filter( 'p3_automatic_scan_urls', array( $this, 'auto_scan_pages' ) ); | |
} | |
public static function activate() { | |
$urls = array( | |
home_url(), | |
admin_url() | |
); | |
update_option( 'p3_customer_urls', $urls ); | |
} | |
public static function uninstall() { | |
if ( defined( 'WP_UNINSTALL_PLUGIN' ) ) { | |
delete_option( 'p3_customizer_urls' ); | |
} | |
} | |
public function register_settings() { | |
$section = 'p3_customizer_settings_section'; | |
$group = 'p3_customizer_settings_group'; | |
add_settings_section( $section, __( 'Settings', 'p3_customizer' ), '__return_null', 'p3_customizer-settings' ); | |
add_settings_field( | |
'p3_customizer_urls', | |
__( 'URLs to Scan', 'p3_customizer' ), | |
array( $this, 'show_p3_customizer_urls' ), | |
'p3_customizer-settings', | |
$section | |
); | |
register_setting( $group, 'p3_customizer_urls' ); | |
} | |
public function auto_scan_pages() { | |
return array_map( 'trim', preg_split( '/\R/', get_option( 'p3_customizer_urls' ) ) ); | |
} | |
public function settings_page() { | |
add_options_page( __( 'P3 Customizer', 'p3_customizer' ), __( 'P3 Customizer', 'p3_customizer' ), 'manage_options', 'p3_customizer-settings', array( $this, 'plugin_options' ) ); | |
} | |
public function plugin_options() { | |
// Check permissions | |
if ( !current_user_can( 'manage_options' ) ) { | |
wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); | |
} | |
?> | |
<div class="wrap"> | |
<div id="icon-tools" class="icon32"><br/></div> | |
<h2><?php _e( 'P3 Customizer', 'p3_customizer' ); ?></h2> | |
<form id="p3_customizer_settings_form" name="p3_customizer_form" method="post" action="options.php"> | |
<?php settings_fields( 'p3_customizer_settings_group' ); ?> | |
<?php do_settings_sections( 'p3_customizer-settings' ); ?> | |
<?php submit_button(); ?> | |
</form> | |
</div> | |
<?php | |
} | |
public function show_p3_customizer_urls() { | |
?> | |
<label for="p3_customizer_urls"> | |
<textarea id="p3_customizer_urls" cols="128" rows="15" name="p3_customizer_urls"><?php echo esc_textarea( get_option( 'p3_customizer_urls' ) ); ?></textarea> | |
</label> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment