in Programming

WordPress Plugin Patch: Subscribe2

I’m working with a network-enabled site, with admin behind SSL. I created a patch for the subscribe2 plugin (Version 6.0) to improve how it worked with the setup. For example, internal links it created were directed to non-https admin pages, which would cause a redirection. Also, assets such as css were not linked via https, causing warnings to appear to people viewing admin pages.

See Github for the patch: //gist.github.com/617790

Platform:

WordPress 3.0.1 Subscribe2: 6.0

Patch is below as well

--- subscribe2.bak.php  2010-10-08 13:05:14.000000000 -0400
+++ subscribe2.php  2010-10-08 14:39:48.000000000 -0400
@@ -53,30 +53,51 @@
 // start our class
 class s2class {

<h2> // variables and constructor are declared at the end</h2>

<ul>
<li>function should_use_ssl() {</li>
<li>return isset($this-&gt;subscribe2_options['use_ssl']) &amp;&amp; $this-&gt;subscribe2_options['use_ssl'] == 'yes';</li>
<li>}
+</li>
<li>function get_home() {</li>
<li>$opt = get_option('home');</li>
<li>return $this-&gt;should_use_ssl() ? $this-&gt;force_ssl($opt) : $opt;</li>
<li>}</li>
<li>

<ul>
<li>function get_content_url() {</li>
</ul></li>
<li>$opt = WP_CONTENT_URL;</li>
<li>return $this-&gt;should_use_ssl() ? $this-&gt;force_ssl($opt) : $opt;</li>
<li>}</li>
<li>

<ul>
<li>function get_siteurl() {</li>
</ul></li>
<li>$opt = get_option('siteurl');</li>
<li>return $this-&gt;should_use_ssl() ? $this-&gt;force_ssl($opt) : $opt;</li>
<li>}</li>
<li>

<ul>
<li>function force_ssl($url) {</li>
</ul></li>
<li>return preg_replace('//i', 'https:', $url);</li>
<li>}
/**
Load all our strings
*/
function load_strings() {
    // adjust the output of Subscribe2 here</li>
<li>$this-&amp;gt;please_log_in = &amp;quot;&amp;lt;p&amp;gt;&amp;quot; . __('To manage your subscription options please', 'subscribe2') . &amp;quot; &amp;lt;a href=\&amp;quot;&amp;quot; . get_option('siteurl') . &amp;quot;/wp-login.php\&amp;quot;&amp;gt;&amp;quot; . __('login', 'subscribe2') . &amp;quot;&amp;lt;/a&amp;gt;.&amp;lt;/p&amp;gt;&amp;quot;;
</li>
<li>$this-&amp;gt;please_log_in = &amp;quot;&amp;lt;p&amp;gt;&amp;quot; . __('To manage your subscription options please', 'subscribe2') . &amp;quot; &amp;lt;a href=\&amp;quot;&amp;quot; . $this-&amp;gt;get_siteurl() . &amp;quot;/wp-login.php\&amp;quot;&amp;gt;&amp;quot; . __('login', 'subscribe2') . &amp;quot;&amp;lt;/a&amp;gt;.&amp;lt;/p&amp;gt;&amp;quot;;
</li>
<li>$this-&amp;gt;use_profile_admin = &amp;quot;&amp;lt;p&amp;gt;&amp;quot; . __('You may manage your subscription options from your', 'subscribe2') . &amp;quot; &amp;lt;a href=\&amp;quot;&amp;quot; . get_option('siteurl') . &amp;quot;/wp-admin/users.php?page=s2_users\&amp;quot;&amp;gt;&amp;quot; . __('profile', 'subscribe2') . &amp;quot;&amp;lt;/a&amp;gt;.&amp;lt;/p&amp;gt;&amp;quot;;
</li>
<li>$this-&gt;use_profile_admin = &quot;&lt;p&gt;&quot; . __('You may manage your subscription options from your', 'subscribe2') . &quot; &lt;a href=\&quot;&quot; . $this-&gt;get_siteurl() . &quot;/wp-admin/users.php?page=s2_users\&quot;&gt;&quot; . __('profile', 'subscribe2') . &quot;&lt;/a&gt;.&lt;/p&gt;&quot;;
    if ( $this-&gt;s2_mu === true) {
        global $blog_id, $user_ID;
        if ( !is_blog_user($blog_id) ) {
            // if we are on multisite and the user is not a member of this blog change the link</li>
<li>$this-&gt;use_profile_admin = &quot;&lt;p&gt;&lt;a href=\&quot;&quot; . get_option('siteurl') . &quot;/wp-admin/?s2mu_subscribe=&quot; . $blog_id . &quot;\&quot;&gt;&quot; . __('Subscribe', 'subscribe2') . &quot;&lt;/a&gt;&quot; . __('to email notifications when this blog posts new content', 'subscribe2') . &quot;.&lt;/p&gt;&quot;;</li>
<li>        $this-&amp;gt;use_profile_admin = &amp;quot;&amp;lt;p&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot; . $this-&amp;gt;get_siteurl() . &amp;quot;/wp-admin/?s2mu_subscribe=&amp;quot; . $blog_id . &amp;quot;\&amp;quot;&amp;gt;&amp;quot; . __('Subscribe', 'subscribe2') . &amp;quot;&amp;lt;/a&amp;gt;&amp;quot; . __('to email notifications when this blog posts new content', 'subscribe2') . &amp;quot;.&amp;lt;/p&amp;gt;&amp;quot;;
    }
}
</li>
<li>$this-&amp;gt;use_profile_users = &amp;quot;&amp;lt;p&amp;gt;&amp;quot; . __('You may manage your subscription options from your', 'subscribe2') . &amp;quot; &amp;lt;a href=\&amp;quot;&amp;quot; . get_option('siteurl') . &amp;quot;/wp-admin/profile.php?page=s2_users\&amp;quot;&amp;gt;&amp;quot; . __('profile', 'subscribe2') . &amp;quot;&amp;lt;/a&amp;gt;.&amp;lt;/p&amp;gt;&amp;quot;;
</li>
<li>$this-&gt;use_profile_users = &quot;&lt;p&gt;&quot; . __('You may manage your subscription options from your', 'subscribe2') . &quot; &lt;a href=\&quot;&quot; . $this-&gt;get_siteurl() . &quot;/wp-admin/profile.php?page=s2_users\&quot;&gt;&quot; . __('profile', 'subscribe2') . &quot;&lt;/a&gt;.&lt;/p&gt;&quot;;
    if ( $this-&gt;s2_mu === true) {
        global $blog_id, $user_ID;
        if ( !is_blog_user($blog_id) ) {
            // if we are on multisite and the user is not a member of this blog change the link</li>
<li>$this-&gt;use_profile_users = &quot;&lt;p&gt;&lt;a href=\&quot;&quot; . get_option('siteurl') . &quot;/wp-admin/?s2mu_subscribe=&quot; . $blog_id . &quot;\&quot;&gt;&quot; . __('Subscribe', 'subscribe2') . &quot;&lt;/a&gt;&quot; . __('to email notifications when this blog posts new content', 'subscribe2') . &quot;.&lt;/p&gt;&quot;;</li>
<li>$this-&gt;use_profile_users = &quot;&lt;p&gt;&lt;a href=\&quot;&quot; . $this-&gt;get_siteurl() . &quot;/wp-admin/?s2mu_subscribe=&quot; . $blog_id . &quot;\&quot;&gt;&quot; . __('Subscribe', 'subscribe2') . &quot;&lt;/a&gt;&quot; . __('to email notifications when this blog posts new content', 'subscribe2') . &quot;.&lt;/p&gt;&quot;;
        }
    }</li>
</ul>

@@ -142,22 +163,22 @@
    Hook for Admin Drop Down Icons
    */
    function ozh_s2_icon() {
-       return WP_CONTENT_URL . '/plugins/' . S2DIR . '/include/email_edit.png';
+       return $this-&gt;get_content_url . '/plugins/' . S2DIR . '/include/email_edit.png';
    } // end ozh_s2_icon()

/**
Insert Javascript into admin_header
*/
function checkbox_form_js() {


-       wp_enqueue_script('s2_checkbox', WP_CONTENT_URL . '/plugins/' . S2DIR . '/include/s2_checkbox.js', array('jquery'), '1.0');
+       wp_enqueue_script('s2_checkbox', $this-&gt;get_content_url . '/plugins/' . S2DIR . '/include/s2_checkbox.js', array('jquery'), '1.0');
    } //end checkbox_form_js()

function user_admin_css() {


-       wp_enqueue_style('s2_user_admin', WP_CONTENT_URL . '/plugins/ '. S2DIR . '/include/s2_user_admin.css', array(), '1.0');
+       wp_enqueue_style('s2_user_admin', $this-&gt;get_content_url . '/plugins/ '. S2DIR . '/include/s2_user_admin.css', array(), '1.0');
    }

function option_form_js() {


-       wp_enqueue_script('s2_edit', WP_CONTENT_URL . '/plugins/' . S2DIR . '/include/s2_edit.js', array('jquery'), '1.0');
+       wp_enqueue_script('s2_edit', $this-&gt;get_content_url . '/plugins/' . S2DIR . '/include/s2_edit.js', array('jquery'), '1.0');
    } // end option_form_js()

/* ===== Install, upgrade, reset ===== */
@@ -301,7 +322,7 @@
            return;
        }
        $string = str_replace(&quot;BLOGNAME&quot;, html_entity_decode(get_option('blogname'), ENT_QUOTES), $string);
-       $string = str_replace(&quot;BLOGLINK&quot;, get_option('home'), $string);
+       $string = str_replace(&quot;BLOGLINK&quot;, $this-&gt;get_home(), $string);
        $string = str_replace(&quot;TITLE&quot;, stripslashes($this-&gt;post_title), $string);
        $link = &quot;&lt;a href=\&quot;&quot; . $this-&gt;permalink . &quot;\&quot;&gt;&quot; . $this-&gt;permalink . &quot;&lt;/a&gt;&quot;;
        $string = str_replace(&quot;PERMALINK&quot;, $link, $string);
@@ -678,7 +699,7 @@
        // HASH = md5 hash of email address
        // ID = user's ID in the subscribe2 table
        // use home instead of siteurl incase index.php is not in core wordpress directory
-       $link = get_option('home') . &quot;/?s2=&quot;;
+       $link = $this-&gt;get_home() . &quot;/?s2=&quot;;

    if ( 'add' == $what ) {
        $link .= '1';


@@ -1384,18 +1405,18 @@
                    switch_to_blog(key($user_blogs));
                } else {
                    // no longer a member of a blog
-                   wp_redirect(get_option('siteurl')); // redirect to front page
+                   wp_redirect($this-&gt;get_siteurl()); // redirect to front page
                    exit();
                }
            }

        // redirect to profile page
        if ( current_user_can('manage_options') ) {


-               $url = get_option('siteurl') . '/wp-admin/users.php?page=s2_users';
+               $url = $this-&gt;get_siteurl() . '/wp-admin/users.php?page=s2_users';
                wp_redirect($url);
                exit();
            } else {
-               $url = get_option('siteurl') . '/wp-admin/profile.php?page=s2_users';
+               $url = $this-&gt;get_siteurl() . '/wp-admin/profile.php?page=s2_users';
                wp_redirect($url);
                exit();
            }
@@ -1585,7 +1606,7 @@

    $reminderform = false;
    $urlpath = str_replace(&amp;quot;\\&amp;quot;, &amp;quot;/&amp;quot;, S2PATH);


-       $urlpath = trailingslashit(get_option('siteurl')) . substr($urlpath,strpos($urlpath, &quot;wp-content/&quot;));
+       $urlpath = trailingslashit($this-&gt;get_siteurl()) . substr($urlpath,strpos($urlpath, &quot;wp-content/&quot;));
        if ( isset($<em>GET['s2page']) ) {
            $page = (int) $_GET['s2page'];
        } else {
@@ -1773,7 +1794,7 @@
                } elseif ( in_array($subscriber, $all_users) ) {
                    echo &quot;&lt;/td&gt;&lt;td align=\&quot;center\&quot;&gt;&lt;/td&gt;&lt;td align=\&quot;center\&quot;&gt;&lt;/td&gt;\r\n&quot;;
                    echo &quot;&lt;td&gt;&lt;span style=\&quot;color:#006600\&quot;&gt;&amp;reg;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;a href=\&quot;mailto:&quot; . $subscriber . &quot;\&quot;&gt;&quot; . $subscriber . &quot;&lt;/a&gt;\r\n&quot;;
-                   echo &quot;(&lt;a href=\&quot;&quot; . get_option('siteurl') . &quot;/wp-admin/users.php?page=s2_users&amp;amp;email=&quot; . urlencode($subscriber) . &quot;\&quot;&gt;&quot; . _</em>('edit', 'subscribe2') . &quot;&lt;/a&gt;)\r\n&quot;;
+                   echo &quot;(&lt;a href=\&quot;&quot; . $this-&gt;get_siteurl() . &quot;/wp-admin/users.php?page=s2_users&amp;amp;email=&quot; . urlencode($subscriber) . &quot;\&quot;&gt;&quot; . __('edit', 'subscribe2') . &quot;&lt;/a&gt;)\r\n&quot;;
                }
                echo &quot;&lt;/td&gt;&lt;/tr&gt;\r\n&quot;;
                ('alternate' == $alternate) ? $alternate = '' : $alternate = 'alternate';
@@ -1855,6 +1876,9 @@
                    echo &quot;&lt;div id=\&quot;message\&quot; class=\&quot;updated fade\&quot;&gt;&lt;p&gt;&lt;strong&gt;&quot; . __('Attempt made to resend the Digest Notification email', 'subscribe2') . &quot;&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;&quot;;
                }
            } elseif ( $_POST['submit'] ) {
+             // security
+             $this-&gt;subscribe2_options['use_ssl'] = $_POST['use_ssl'];
+<br />
                // BCClimit
                if ( is_numeric($_POST['bcc']) &amp;&amp; $_POST['bcc'] &gt;= 0 ) {
                    $this-&gt;subscribe2_options['bcclimit'] = $_POST['bcc'];
@@ -1875,6 +1899,7 @@
                $this-&gt;subscribe2_options['password'] = $_POST['password'];
                $this-&gt;subscribe2_options['private'] = $_POST['private'];
                $this-&gt;subscribe2_options['cron_order'] = $_POST['cron_order'];
+

            // send per-post or digest emails
            $email_freq = $_POST['email_freq'];


@@ -2009,6 +2034,15 @@
        echo &quot;&lt;input type=\&quot;hidden\&quot; id=\&quot;jspage\&quot; value=\&quot;&quot; . $this-&gt;subscribe2_options['s2page'] . &quot;\&quot; /&gt;&quot;;
        echo &quot;&lt;input type=\&quot;hidden\&quot; id=\&quot;jsentries\&quot; value=\&quot;&quot; . $this-&gt;subscribe2_options['entries'] . &quot;\&quot; /&gt;&quot;;

<ul>
<li>echo &quot;&lt;h2&gt;&quot; . __('Security Settings', 'subscribe2') . &quot;&lt;/h2&gt;\r\n&quot;;</li>
<li>echo __('Use SSL Links', 'subscribe2') . ': ';</li>
<li>echo &quot;&lt;label&gt;&lt;input type=\&quot;checkbox\&quot; name=\&quot;use_ssl\&quot; value=\&quot;yes\&quot;&quot;;</li>
<li>if ( $this-&gt;should_use_ssl() ) {</li>
<li>echo &quot; checked=\&quot;checked\&quot;&quot;;</li>
<li>}</li>
<li>echo '/&gt; '.__('Forces http links to https for key pages', 'subscribe2');</li>
<li>
+
    // settings for outgoing emails
    echo &quot;&lt;h2&gt;&quot; . __('Notification Settings', 'subscribe2') . &quot;&lt;/h2&gt;\r\n&quot;;
    echo __('Restrict the number of recipients per email to (0 for unlimited)', 'subscribe2') . ': ';
@@ -2121,7 +2155,7 @@
    echo &quot;&lt;h3&gt;&quot; . __('Message substitions', 'subscribe2') . &quot;&lt;/h3&gt;\r\n&quot;;
    echo &quot;&lt;dl&gt;&quot;;
    echo &quot;&lt;dt&gt;&lt;b&gt;BLOGNAME&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&quot; . get_option('blogname') . &quot;&lt;/dd&gt;\r\n&quot;;</li>
<li>echo &quot;&lt;dt&gt;&lt;b&gt;BLOGLINK&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&quot; . get_option('home') . &quot;&lt;/dd&gt;\r\n&quot;;</li>
<li>echo &quot;&lt;dt&gt;&lt;b&gt;BLOGLINK&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&quot; . $this-&gt;get_home() . &quot;&lt;/dd&gt;\r\n&quot;;
    echo &quot;&lt;dt&gt;&lt;b&gt;TITLE&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&quot; . __(&quot;the post's title&lt;br /&gt;(&lt;i&gt;for per-post emails only&lt;/i&gt;)&quot;, 'subscribe2') . &quot;&lt;/dd&gt;\r\n&quot;;
    echo &quot;&lt;dt&gt;&lt;b&gt;POST&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&quot; . __(&quot;the excerpt or the entire post&lt;br /&gt;(&lt;i&gt;based on the subscriber's preferences&lt;/i&gt;)&quot;, 'subscribe2') . &quot;&lt;/dd&gt;\r\n&quot;;
    echo &quot;&lt;dt&gt;&lt;b&gt;POSTTIME&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&quot; . __(&quot;the excerpt of the post and the time it was posted&lt;br /&gt;(&lt;i&gt;for digest emails only&lt;/i&gt;)&quot;, 'subscribe2') . &quot;&lt;/dd&gt;\r\n&quot;;
@@ -2449,11 +2483,11 @@
            $subscribed = get_usermeta($user_ID, $this-&gt;get_usermeta_keyname('s2_subscribed'));
            // if we are subscribed to the current blog display an &quot;unsubscribe&quot; link
            if ( !empty($subscribed) ) {</li>
<li>$unsubscribe_link = get_option('home') . &quot;/wp-admin/?s2mu_unsubscribe=&quot;. $blog_id;</li>
<li>$unsubscribe_link = $this-&gt;get_home() . &quot;/wp-admin/?s2mu_unsubscribe=&quot;. $blog_id;
                echo &quot;&lt;p&gt;&lt;a href=\&quot;&quot;. $unsubscribe_link .&quot;\&quot; class=\&quot;button\&quot;&gt;&quot; . __('Unsubscribe me from this blog', 'subscribe2') . &quot;&lt;/a&gt;&lt;/p&gt;&quot;;
            } else {
                // else we show a &quot;subscribe&quot; link</li>
<li>$subscribe_link = get_option('home') . &quot;/wp-admin/?s2mu_subscribe=&quot;. $blog_id;</li>
<li>$subscribe_link = $this-&gt;get_home() . &quot;/wp-admin/?s2mu_subscribe=&quot;. $blog_id;
                echo &quot;&lt;p&gt;&lt;a href=\&quot;&quot;. $subscribe_link .&quot;\&quot; class=\&quot;button\&quot;&gt;&quot; . __('Subscribe to all categories', 'subscribe2') . &quot;&lt;/a&gt;&lt;/p&gt;&quot;;
            }
            echo &quot;&lt;h2&gt;&quot; . __('Subscribed Categories on', 'subscribe2') . &quot; &quot; . get_option('blogname') . &quot; &lt;/h2&gt;\r\n&quot;;
@@ -2514,8 +2548,8 @@
                $blog['blogname'] = $blogname;
            }
            $blog['description'] = get_option('blogdescription');</li>
<li>$blog['blogurl'] = get_option('home');</li>
<li>$blog['subscribe_page'] = get_option('home') . &quot;/wp-admin/users.php?page=s2_users&quot;;</li>
<li>$blog['blogurl'] = $this-&gt;get_home();</li>
<li>        $blog['subscribe_page'] = $this-&amp;gt;get_home() . &amp;quot;/wp-admin/users.php?page=s2_users&amp;quot;;

        $key = strtolower($blog['blogname'] . &amp;quot;-&amp;quot; . $blog['blog_id']);
        if ( !empty($subscribed) ) {


@@ -3210,7 +3244,7 @@
Function to add js files to admin header
*/
function widget_s2counter_js() {</li>
<li>echo '&lt;script type=&quot;text/javascript&quot; src=&quot;' . WP_CONTENT_URL . '/plugins/' . S2DIR . '/include/colorpicker/js/colorpicker.js&quot;&gt;&lt;/script&gt;' . &quot;\r\n&quot;;</li>
<li>echo '&lt;script type=&quot;text/javascript&quot; src=&quot;' . $this-&gt;get_content_url . '/plugins/' . S2DIR . '/include/colorpicker/js/colorpicker.js&quot;&gt;&lt;/script&gt;' . &quot;\r\n&quot;;
    echo &quot;&lt;script type=\&quot;text/javascript\&quot;&gt;
        jQuery(document).ready(function() {
            jQuery('.colorpickerField').focusin(function() {
@@ -3239,7 +3273,7 @@
Function to add css files to admin header
*/
function widget_s2counter_css() {</li>
<li>echo '&lt;link rel=&quot;stylesheet&quot; href=&quot;' . WP_CONTENT_URL . '/plugins/' . S2DIR . '/include/colorpicker/css/colorpicker.css&quot; type=&quot;text/css&quot; /&gt;' . &quot;\r\n&quot;;</li>
<li>echo '&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;' . $this-&amp;gt;get_content_url . '/plugins/' . S2DIR . '/include/colorpicker/css/colorpicker.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;' . &amp;quot;\r\n&amp;quot;;


} // end widget_s2counter_css

function namechange_subscribe2_widget() {
@@ -3274,7 +3308,7 @@
*/
function add_minimeta() {
    if ( $this-&gt;subscribe2_options['s2page'] != 0 ) {</li>
<li>echo &quot;&lt;li&gt;&lt;a href=\&quot;&quot; . get_option('siteurl') . &quot;/?page_id=&quot; . $this-&gt;subscribe2_options['s2page'] . &quot;\&quot;&gt;&quot; . __('[Un]Subscribe to Posts', 'subscribe2') . &quot;&lt;/a&gt;&lt;/li&gt;\r\n&quot;;</li>
<li>echo &quot;&lt;li&gt;&lt;a href=\&quot;&quot; . $this-&gt;get_siteurl() . &quot;/?page_id=&quot; . $this-&gt;subscribe2_options['s2page'] . &quot;\&quot;&gt;&quot; . __('[Un]Subscribe to Posts', 'subscribe2') . &quot;&lt;/a&gt;&lt;/li&gt;\r\n&quot;;
    }
} // end add_minimeta()</li>
</ul>

@@ -3291,7 +3325,7 @@
            add_filter('mce_buttons', array(&amp;$this, 'mce3_button'));
        } else {
            buttonsnap_separator();
-           buttonsnap_jsbutton(WP_CONTENT_URL . '/plugins/' . S2DIR . '/include/s2_button.png', __('Subscribe2', 'subscribe2'), 's2_insert_token();');
+           buttonsnap_jsbutton($this-&gt;get_content_url . '/plugins/' . S2DIR . '/include/s2_button.png', __('Subscribe2', 'subscribe2'), 's2_insert_token();');
        }
    } // end button_init()

@@ -3299,7 +3333,7 @@
    Add buttons for WordPress 2.5+ using built in hooks
    */
    function mce3_plugin($arr) {
-       $path = WP_CONTENT_URL . '/plugins/' . S2DIR . '/tinymce3/editor_plugin.js';
+       $path = $this-&gt;get_content_url . '/plugins/' . S2DIR . '/tinymce3/editor_plugin.js';
        $arr['subscribe2'] = $path;
        return $arr;
    }
@@ -3699,4 +3733,4 @@
    var $options_saved = '';
    var $options_reset = '';
 } // end class subscribe2
-?&gt;
\ No newline at end of file
+?&gt;