The MU forums have moved to WordPress.org

need some help with some php code (5 posts)

  1. Ovidiu
    Member
    Posted 13 years ago #

    I would love to modify the sharethis plugin (http://sharethis.com)in the way of changing the default options it comes with.

    here is the code I picked out for changing:

    $options = array(
    		'st_add_to_content' => __('Automatically add ShareThis to your posts?*', 'sharethis')
    		, 'st_add_to_page' => __('Automatically add ShareThis to your pages?*', 'sharethis')
    	);
    	foreach ($options as $option => $description) {
    		$$option = get_option($option);
    		if (empty($$option) || $$option == 'no') {
    			$yes = '';
    			$no = ' selected="selected"';
    		}
    		else {
    			$yes = ' selected="selected"';
    			$no = '';
    		}
    		print('
    						<p>
    							<label for="'.$option.'">'.$description.'</label>
    							<select name="'.$option.'" id="'.$option.'">
    								<option value="yes"'.$yes.'>'.__('Yes', 'sharethis').'</option>
    								<option value="no"'.$no.'>'.__('No', 'sharethis').'</option>
    							</select>
    						</p>
    		');
    	}

    I think changing this:

    if (empty($$option) || $$option == 'no') {
    			$yes = '';
    			$no = ' selected="selected"';
    		}

    should set the default settings so that ShareThis is not automatically added, right?

  2. Ovidiu
    Member
    Posted 13 years ago #

    guys I suck at php, please just have a glance at it.

  3. dsader
    Member
    Posted 13 years ago #

    Glancing at the code, what you've done changed the options page but the options only update to yes or no after the first save at the options page. You'll also need to change the "!= 'no'" to "=='yes'" if you want the "share this" buttons to only appear after options are in fact changed to "yes".

    "!='no'" means a "yes" or empty(default) option displays the button. "=='yes'" means only "yes" displays the buttons.

    So,

    if (get_option('st_add_to_content') != 'no' || get_option('st_add_to_page') != 'no') {
    	add_filter('the_content', 'st_add_widget');

    becomes

    if (get_option('st_add_to_content') =='yes' || get_option('st_add_to_page') =='yes') {
    	add_filter('the_content', 'st_add_widget');

    and

    if ((is_page() && get_option('st_add_to_page') != 'no') || (!is_page() && get_option('st_add_to_content') != 'no'))

    becomes

    if ((is_page() && get_option('st_add_to_page') == 'yes') || (!is_page() && get_option('st_add_to_content') == 'yes'))

  4. Ovidiu
    Member
    Posted 13 years ago #

    got stuck :-(

    anyone willing to modify the sharethis plugin so that the options are only shown to the site admin and it does not get automatically injected on posts or pages as I want to call it manually in a position of my liking.

    I'll donate 5-10$ to whoever does this for me.

  5. rizapn
    Member
    Posted 13 years ago #

    @odiviu : Check your mail ...

About this Topic