Skip to content

Commit

Permalink
Allow Multisite Network Activate, Uses WordPress uninstall.php file t…
Browse files Browse the repository at this point in the history
…o uninstall the plugin
  • Loading branch information
lesterchan committed Apr 28, 2014
1 parent 2122b85 commit ab611eb
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 124 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -4,7 +4,7 @@ Donate link: http://lesterchan.net/site/donation/
Tags: print, printer, wp-print
Requires at least: 2.8
Tested up to: 3.9
Stable tag: 2.53
Stable tag: 2.54

Displays a printable version of your WordPress blog's post/page.

Expand Down Expand Up @@ -93,6 +93,10 @@ if(function_exists('wp_print')) {

## Changelog

### 2.54
* NEW: Allow Multisite Network Activate
* NEW: Uses WordPress uninstall.php file to uninstall the plugin

### 2.53
* FIXED: Use get_stylesheet_directory() instead of TEMPLATEPATH

Expand Down
102 changes: 2 additions & 100 deletions print-options.php
@@ -1,18 +1,4 @@
<?php
/*
* WordPress Plugin: WP-Print
* Copyright (c) 2013 Lester "GaMerZ" Chan
*
* File Written By:
* - Lester "GaMerZ" Chan
* - http://lesterchan.net
*
* File Information:
* - Print Options Page
* - wp-content/plugins/wp-print/print-options.php
*/


### Variables Variables Variables
$base_name = plugin_basename('wp-print/print-options.php');
$base_page = 'admin.php?page='.$base_name;
Expand Down Expand Up @@ -51,49 +37,8 @@
$text = '<font color="red">'.__('No Print Option Updated', 'wp-print').'</font>';
}
}
// Uninstall WP-Print
if(!empty($_POST['do'])) {
switch($_POST['do']) {
case __('UNINSTALL WP-Print', 'wp-print') :
if(trim($_POST['uninstall_print_yes']) == 'yes') {
echo '<div id="message" class="updated fade">';
echo '<p>';
foreach($print_settings as $setting) {
$delete_setting = delete_option($setting);
if($delete_setting) {
echo '<font color="green">';
printf(__('Setting Key \'%s\' has been deleted.', 'wp-print'), "<strong><em>{$setting}</em></strong>");
echo '</font><br />';
} else {
echo '<font color="red">';
printf(__('Error deleting Setting Key \'%s\'.', 'wp-print'), "<strong><em>{$setting}</em></strong>");
echo '</font><br />';
}
}
echo '</p>';
echo '</div>';
$mode = 'end-UNINSTALL';
}
break;
}
}

### Determines Which Mode It Is
switch($mode) {
// Deactivating WP-Print
case 'end-UNINSTALL':
$deactivate_url = 'plugins.php?action=deactivate&amp;plugin=wp-print/wp-print.php';
if(function_exists('wp_nonce_url')) {
$deactivate_url = wp_nonce_url($deactivate_url, 'deactivate-plugin_wp-print/wp-print.php');
}
echo '<div class="wrap">';
echo '<h2>'.__('Uninstall WP-Print', 'wp-print').'</h2>';
echo '<p><strong>'.sprintf(__('<a href="%s">Click Here</a> To Finish The Uninstallation And WP-Print Will Be Deactivated Automatically.', 'wp-print'), $deactivate_url).'</strong></p>';
echo '</div>';
break;
// Main Page
default:
$print_options = get_option('print_options');
$print_options = get_option('print_options');
?>
<script type="text/javascript">
/* <![CDATA[*/
Expand Down Expand Up @@ -242,47 +187,4 @@ function print_default_templates(template) {
<input type="submit" name="Submit" class="button" value="<?php _e('Save Changes', 'wp-print'); ?>" />
</p>
</div>
</form>
<p>&nbsp;</p>

<!-- Uninstall WP-Print -->
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
<div class="wrap">
<h3><?php _e('Uninstall WP-Print', 'wp-print'); ?></h3>
<p>
<?php _e('Deactivating WP-Print plugin does not remove any data that may have been created, such as the print options. To completely remove this plugin, you can uninstall it here.', 'wp-print'); ?>
</p>
<p style="color: red">
<strong><?php _e('WARNING:', 'wp-print'); ?></strong><br />
<?php _e('Once uninstalled, this cannot be undone. You should use a Database Backup plugin of WordPress to back up all the data first.', 'wp-print'); ?>
</p>
<p style="color: red">
<strong><?php _e('The following WordPress Options will be DELETED:', 'wp-print'); ?></strong><br />
</p>
<table class="widefat">
<thead>
<tr>
<th><?php _e('WordPress Options', 'wp-print'); ?></th>
</tr>
</thead>
<tr>
<td valign="top">
<ol>
<?php
foreach($print_settings as $settings) {
echo '<li>'.$settings.'</li>'."\n";
}
?>
</ol>
</td>
</tr>
</table>
<p>&nbsp;</p>
<p style="text-align: center;">
<input type="checkbox" name="uninstall_print_yes" value="yes" />&nbsp;<?php _e('Yes', 'wp-print'); ?><br /><br />
<input type="submit" name="do" value="<?php _e('UNINSTALL WP-Print', 'wp-print'); ?>" class="button" onclick="return confirm('<?php _e('You Are About To Uninstall WP-Print From WordPress.\nThis Action Is Not Reversible.\n\n Choose [Cancel] To Stop, [OK] To Uninstall.', 'wp-print'); ?>')" />
</p>
</div>
</form>
<?php
} // End switch($mode)
</form>
23 changes: 23 additions & 0 deletions uninstall.php
@@ -0,0 +1,23 @@
<?php
/*
* Uninstall plugin
*/
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
exit ();

$option_name = 'print_options';

if ( is_multisite() ) {
$ms_sites = wp_get_sites();

if( 0 < sizeof( $ms_sites ) ) {
foreach ( $ms_sites as $ms_site ) {
switch_to_blog( $ms_site['blog_id'] );
delete_option( $option_name );
}
}

restore_current_blog();
} else {
delete_option( $option_name );
}
71 changes: 48 additions & 23 deletions wp-print.php
Expand Up @@ -3,15 +3,15 @@
Plugin Name: WP-Print
Plugin URI: http://lesterchan.net/portfolio/programming/php/
Description: Displays a printable version of your WordPress blog's post/page.
Version: 2.53
Version: 2.54
Author: Lester 'GaMerZ' Chan
Author URI: http://lesterchan.net
Text Domain: wp-print
*/


/*
Copyright 2013 Lester Chan (email : lesterchan@gmail.com)
Copyright 2014 Lester Chan (email : lesterchan@gmail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -30,18 +30,16 @@


### Create Text Domain For Translations
add_action('init', 'print_textdomain');
add_action( 'plugins_loaded', 'print_textdomain' );
function print_textdomain() {
load_plugin_textdomain('wp-print', false, 'wp-print');
load_plugin_textdomain( 'wp-print', false, dirname( plugin_basename( __FILE__ ) ) );
}


### Function: Print Option Menu
add_action('admin_menu', 'print_menu');
function print_menu() {
if (function_exists('add_options_page')) {
add_options_page(__('Print', 'wp-print'), __('Print', 'wp-print'), 'manage_options', 'wp-print/print-options.php') ;
}
add_options_page(__('Print', 'wp-print'), __('Print', 'wp-print'), 'manage_options', 'wp-print/print-options.php') ;
}


Expand Down Expand Up @@ -435,21 +433,48 @@ function str_replace_one($search, $replace, $content){
}


### Function: Print Options
add_action('activate_wp-print/wp-print.php', 'print_init');
function print_init() {
print_textdomain();
### Function: Activate Plugin
register_activation_hook( __FILE__, 'print_activation' );
function print_activation( $network_wide )
{
// Add Options
$print_options = array();
$print_options['post_text'] = __('Print This Post', 'wp-print');
$print_options['page_text'] = __('Print This Page', 'wp-print');
$print_options['print_icon'] = 'print.gif';
$print_options['print_style'] = 1;
$print_options['print_html'] = '<a href="%PRINT_URL%" rel="nofollow" title="%PRINT_TEXT%">%PRINT_TEXT%</a>';
$print_options['comments'] = 0;
$print_options['links'] = 1;
$print_options['images'] = 1;
$print_options['videos'] = 0;
$print_options['disclaimer'] = sprintf(__('Copyright &copy; %s %s. All rights reserved.', 'wp-print'), date('Y'), get_option('blogname'));
add_option('print_options', $print_options, 'Print Options');
$option_name = 'print_options';
$option = array(
'post_text' => __('Print This Post', 'wp-print')
, 'page_text' => __('Print This Page', 'wp-print')
, 'print_icon' => 'print.gif'
, 'print_style' => 1
, 'print_html' => '<a href="%PRINT_URL%" rel="nofollow" title="%PRINT_TEXT%">%PRINT_TEXT%</a>'
, 'comments' => 0
, 'links' => 1
, 'images' => 1
, 'videos' => 0
, 'disclaimer' => sprintf(__('Copyright &copy; %s %s. All rights reserved.', 'wp-print'), date('Y'), get_option('blogname'))
);

if ( is_multisite() && $network_wide )
{
$ms_sites = wp_get_sites();

if( 0 < sizeof( $ms_sites ) )
{
foreach ( $ms_sites as $ms_site )
{
switch_to_blog( $ms_site['blog_id'] );
add_option( $option_name, $option );
print_activate();
}
}

restore_current_blog();
}
else
{
add_option( $option_name, $option );
print_activate();
}
}

function print_activate() {
flush_rewrite_rules();
}

0 comments on commit ab611eb

Please sign in to comment.