Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

ConduciveMammal on "Random textfield placeholder"

$
0
0

I'd like to have a textfield with a placeholder and each time the page is loaded, I'd like it to display a different placeholder, maybe read each one from a file and display each line on a random sequence whenever the page loads.

Does anyone know how I can do this?

Thanks.


miowebdesigns on "Extra spaces in vcard download file"

$
0
0

I have a vcard program that I have never used within Wordpress. It is the basic vcard creation that you can find on any website.

print <<<END
BEGIN:VCARD
VERSION:3.0
N:$last;$first;$middle;;;
FN:$fullname
TITLE:$title
PHOTO;VALUE=URL;TYPE=JPG:$path$photo
ORG:$office
TEL;WORK;VOICE:$tel
TEL;WORK;FAX:$fax
EMAIL;TYPE=PREF;INTERNET:$attorney_email
ADR;WORK;ENCODING=QUOTED-PRINTABLE:;;$address=0D=0A$address2;$city;$state;$zip;$country;
URL;TYPE=WORK:http://criminallawsexcrimessacramento.com/
END:VCARD
END;

$output = ob_get_contents();

header('Content-Type: text/x-vcard');
header('Content-Disposition: attachment; filename=vCard_' . $filename . '.vcf');
echo trim($output);
exit();

The problem is the output has extra leading zeros. When I use this code on a php site, not Wordpress, the output has no extra spaces. Not sure why the extra spaces are happening or how to remove them. As you can see in the code I am using trim().
example of file
"
BEGIN:VCARD
VERSION:3.0
N:Daly;Kresta;N.;;;
FN:Kresta N. Daly
TITLE:Partner
PHOTO;VALUE=URL;TYPE=JPG:http://kd.bothwip2013.com//images/attorney_photos/kresta-image.png
ORG:Sacramento
TEL;WORK;VOICE:(916) 440-8600
TEL;WORK;FAX:(916) 440-9610
EMAIL;TYPE=PREF;INTERNET:kdaly@barth-daly.com
ADR;WORK;ENCODING=QUOTED-PRINTABLE:;;431 I Street, Suite 201=0D=0A;Sacramento;CA;95814;United States;
URL;TYPE=WORK:http://criminallawsexcrimessacramento.com/
END:VCARD"

Thanks for any suggestions.
Michael

eyoung100 on "Customized Plugin Content Updating -- Best Way"

$
0
0

I apologize as I may have posted this in the wrong category. It may fit better here. If so, would a mod please delete the original:

I'm relatively new to WordPress, but I'm a programmer for a living. Because of that, I don't like reinventing the wheel. Recently, I downloaded a plugin. I can modify this post to say what the plugin was if needed, but this is more generalized. This plugin tracks items, and creates newsletters based on those tracked items.

One of those items is Gender. Since the visitors I get are sometimes couples, they share email addresses(email is a required field), therefore I cant demand of them to each have an email, so in the Gender Field, I added Couple, tested it, and it works great. Adds an m for male, f for female, and a c for couple to the plugin's customized table in the WordPress Database.

Recently, the plugin had an update, and I updated it. Because I modified pieces in the plugin's core files, the update overwrote the custom field I added, causing me to have to re-add the custom work I did. Can someone tell me what the best approach is to customizing the plugin, while keeping it up to date? Is there a hook I can use/add that will accomplish what I'm asking etc.?

dannymh on "simplepie to grab RSS comments list"

$
0
0

Hi All,

I have some code that integrate my forums post comments to thread replies as comments on the thread.

To do this I use simplepie to hit a custom page on my forum which runs the a few queries

1 - Get the link (the threadid from the custom table)
2 - Get the thread and replies
3 - count the replies

The page outputs XML and is then simplepie interprets this into comment and comment count.

This happens for every wordpress post. Both on the front page and on the post pages (though on the post page it only happens for the specific post we are on)

I think that this likely causes a fair bit of load issues as I have over 5000 posts on my wordpress site.

Just wondering if there may be a better way that will cause less load to grab all of the comments rather than the multiple queries and XML?

I am using 3600 cache and 30 second timeout on this as well

Dan

My on "Taxonomyextra fields?"

$
0
0

I found this code that I can add to the functions file to have extra fields for categories to show up in admin.

//add extra fields to category edit form hook
add_action ( 'edit_category_form_fields', 'extra_category_fields');
//add extra fields to category edit form callback function
function extra_category_fields( $tag ) {    //check for existing featured ID
    $t_id = $tag->term_id;
    $cat_meta = get_option( "category_$t_id");
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="cat_Image_url"><?php _e('Category Image Url'); ?></label></th>
<td>
<input type="text" name="Cat_meta[img]" id="Cat_meta[img]" size="3" style="width:60%;" value="<?php echo $cat_meta['img'] ? $cat_meta['img'] : ''; ?>"><br />
            <span class="description"><?php _e('Image for category: use full url with http://'); ?></span>
        </td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="extra1"><?php _e('extra field'); ?></label></th>
<td>
<input type="text" name="Cat_meta[extra1]" id="Cat_meta[extra1]" size="25" style="width:60%;" value="<?php echo $cat_meta['extra1'] ? $cat_meta['extra1'] : ''; ?>"><br />
            <span class="description"><?php _e('extra field'); ?></span>
        </td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="extra2"><?php _e('extra field'); ?></label></th>
<td>
<input type="text" name="Cat_meta[extra2]" id="Cat_meta[extra2]" size="25" style="width:60%;" value="<?php echo $cat_meta['extra2'] ? $cat_meta['extra2'] : ''; ?>"><br />
            <span class="description"><?php _e('extra field'); ?></span>
        </td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="extra3"><?php _e('extra field'); ?></label></th>
<td>
            <textarea name="Cat_meta[extra3]" id="Cat_meta[extra3]" style="width:60%;"><?php echo $cat_meta['extra3'] ? $cat_meta['extra3'] : ''; ?></textarea><br />
            <span class="description"><?php _e('extra field'); ?></span>
        </td>
</tr>
<?php
}

However, I would like the extra fields to appear in a new post type/Taxonomy that I created - how do I do that?

Other questions:

- Is it possible to have one of the extra fields to be a file upload?
- How do I call the extra fields in my theme so they show up in the front end?

Thanks <3

My on "Taxonomies in functions or plugin?"

$
0
0

I have read some tutorials on taxonomies where it's added in the theme function file. And some say this is not good.

Why is it not good to it that way? And what is a better way to do it?

miowebdesigns on "Calling outside programs with $_GET"

$
0
0

Here is the thing. I have created a site and on it we need to call a program that downloads vcards, one for each employee. That means I need to pass the id for that employee. I am trying $_GET. I have tried a straight call passing the parm. I tried creating a page and passing the parm thru the page. Here is a link: http://hsm.bothwip2013.com/attorneys/. I have never attempted this before. Any ideas?
Two samples of code attempted:

<a href=\"http://hsm.bothwip2013.com/atty-vcard/?id=$attorney_id\" class=\"atty-vcard\" title=\"Download Vcard\">

<a href=\""; ?>
<?php bloginfo('template_url'); ?>
<? echo "child/attorney-vcard.php?id=$attorney_id\" class=\"atty-vcard\" title=\"Download Vcard\">

Thanks

Unico1242yahoo.com on "how to recover archives after being hacked"

$
0
0

I have been blogging for 3 1/2 years. Then someone hacked onto the blog and started posting as "author". The posts seemed spam-like in nature in that they seemed like key search engine words for pharmaceuticals and nike sneakers. I tried to get help from yahoo but that went no where. So then I went into the site and started changing all the "authors" who had been posting, to "Subscribers". The next day, when I opened the blog, all my posts and archives were GONE. There is a lot of material contained in the archives that has a lot of sentimental meaning for myself and others. I'm not horribly savy tech. wise but I'm not dense either so please advise.
http://www.luckycharmfarm.com/blog theme: Twenty Ten 1.2 by the WordPress team
Here is a list of my plug-ins to assist you:
Add to My Yahoo! Button
After The Deadline
Akismet
Customizable Permalinks
Hosted by Yahoo! Badge
WordPress Database Backup
Yahoo! Blog Statistics
Yahoo! Search Box
These are on my Dashboard but not activated:
FAlbum
Subscribe2
wp-cache


Metal_13 on "How to change playlists mp3 url to attachment page url"

$
0
0

data.src goes directly to the mp3 file, how do i change the link to the attachment page?

the closest i got was "data.title", but it has spaces in it and the attachment page doesn't...

please help me with this..

wp-includes/media.php Line: 1108

/**
 * Output the templates used by playlists.
 *
 * @since 3.9.0
 */
function wp_underscore_playlist_templates() {
?>
<script type="text/html" id="tmpl-wp-playlist-current-item">
	<# if ( data.image ) { #>
	<img src="{{ data.thumb.src }}"/>
	<# } #>
	<div class="wp-playlist-caption">
		<span class="wp-playlist-item-meta wp-playlist-item-title">“{{ data.title }}”</span>
		<# if ( data.meta.album ) { #><span class="wp-playlist-item-meta wp-playlist-item-album">{{ data.meta.album }}</span><# } #>
		<# if ( data.meta.artist ) { #><span class="wp-playlist-item-meta wp-playlist-item-artist">{{ data.meta.artist }}</span><# } #>
	</div>
</script>
<script type="text/html" id="tmpl-wp-playlist-item">
	<div class="wp-playlist-item">
		<a class="wp-playlist-caption" href="{{ data.src }}">
			{{ data.index ? ( data.index + '. ' ) : '' }}
			<# if ( data.caption ) { #>
				{{ data.caption }}
			<# } else { #>
				<span class="wp-playlist-item-title">“{{{ data.title }}}”</span>
				<# if ( data.artists && data.meta.artist ) { #>
				<span class="wp-playlist-item-artist"> &mdash; {{ data.meta.artist }}</span>
				<# } #>
			<# } #>
		</a>
		<# if ( data.meta.length_formatted ) { #>
		<div class="wp-playlist-item-length">{{ data.meta.length_formatted }}</div>
		<# } #>
	</div>
</script>

ADKSherpa on "Web Exclusive Headline Icon"

$
0
0

How might it be possible to add a little icon to the end of a post's title to denote that it's a "web exclusive" (i.e. in a category I call "Web Exclusive")?

Ideally, just by adding it to the category, it would automatically add the icon. Even more ideally that icon would link to the archive for said category.

Any guesses?

Robodashy on "Database custom table issues - incorrect result displayed"

$
0
0

I tried to put code in the backticks like it says, so just ignore any ''s that look out of place (unless it's blatantly not me trying to do that)

First things first:
I've spent most of today going over these forums;
the stackoverflow forums;
the php.net manual; and
a bunch of random sites I found through Google Search - so,
if I've missed the answer and it seems like I'm asking an already answered question I'm sorry.
I've probably just been looking at the same problem for way too long and nothing is making sense.

The background:

We've inserted some custom tables into the wordpress database, so I can connect to these tables through $wpdb. The code for the working connections is as follows:

'global $wpdb;
// get list of localities
$localityRow = $wpdb->get_results( "SELECT * FROM tblYBSLocality ORDER BY Name ASC" );
// get list of schools
$schoolRow = $wpdb->get_results( "SELECT * FROM tblYBSSchool ORDER BY Name ASC" );
// get school ID if form has been submitted
$SelectedSchoolID = $_GET['schools'];
// get location ID if form has been submitted
$SelectedLocationID = $_GET['localities'];'

Then later in my page I make it do stuff (scorcery!)

'// Create a drop down box for the user to select their location (and one has been done for school but I left that out because you get the idea
<select name="localities" style="width: 300px">
<?php
foreach ($localityRow as $locality) {
$LocalityID = $locality->LocalityID;
$LocalityName = $locality->Name;
?>

<option value=<?php echo $LocalityID; ?> <?php if(isset($SelectedLocationID) &&
$SelectedLocationID == $LocalityID) print(" selected")?>><?php echo $LocalityName;?>
</option>
<?php
}
?>
</select>'

Note - Yes I know using * is bad, I'll fix that later - right now I just want it to work.

Using this I can then go through and generate a bunch of stuff using the following:

'// get school ID if form has been submitted
$SelectedSchoolID = $_GET['schools'];
// get location ID if form has been submitted
$SelectedLocationID = $_GET['localities'];'

This isn't really important to the rest of my issue, so I'll move on.

The issue:

I'll start with the code. This is supposed to connect to some other tables and do stuff - based on the connections and data retrieved above:

'$selectedSchoolName = $wpdb->get_results( "SELECT Name FROM tblYBSSchool WHERE SchoolID=".$SelectedSchoolID );
// get selected location name
$selectedLocationName = $wpdb->get_results( "SELECT Name FROM tblYBSLocality WHERE LocalityID=".$SelectedLocationID );
// get route ID
$getRouteID = $wpdb->get_results( "SELECT * FROM tblYBSRoute WHERE RouteID IN ( SELECT RouteID FROM tblYBSRouteSchool WHERE SchoolID =".$SelectedSchoolID.")".$SelectedLocationID);'

Now, I THINK the issue comes with the ".$SelectedSchoolID ); part (and the location one but this is already getting TLDR).

What I want to do later in the page (once the user has made their selections and submitted the form), is get results (fancy that!).

There are 2 parts to the results:

1st I want to say "Search results for routes between:" the location name and the school name.
2nd, I want to display those results. But I can't even get past the 1st point, so let's fix that first.

I have tried 3 different approaches:

'// FIRST APPROACH
// This kinda works, it echoes the last locality name from the table which is better than nothing
<b><?php echo $LocalityName;?></b> and <b><?php echo $SchoolName;?></b>

// SECOND APPROACH
// This gives me the white page of death. Which is hilarious because it's pretty much the exact same as what was used in the option - which worked
<b><?php if(isset($SelectedLocationID) && $SelectedLocationID == $LocalityID) echo $LocalityName;?></b> and <b><?php if(isset($SelectedSchoolID) && $SelectedSchoolID == $SchoolID) echo $SchoolName;?></b>

// THIRD APPROACH
// This also gives me the white page of death. And now I'm out of ideas.
<b><?php if(isset($SelectedLocationID) && $selectedLocationName == $LocalityName echo $LocalityName ;?></b> and <b><?php if(isset($SelectedSchoolID) && $selectedSchoolName == $SchoolName echo $SchoolName ;?></b>'

In my head (HAH!) the last 2 should work. Am I correct in thinking that it's the ".$SelectedSchoolID ); part? Or have I forked something else up entirely?

Sorry for the TLDRness, but I thought I should provide as much detail as possible.
Any and all help is greatly appreciated. I'm going to go smack my head into the desk a few times now :P

Mudplugger on "Making Spider Event Calendar available to users other than Admins"

$
0
0

A Few people including me have asked the plugin author if this is possible and while it is not a feature of the plugin itself I have a work around that enables the requested functionality.

This information is supplied as is and does not come with any warranty. Basically the information here allows for a greater level of control over which users of your site can add events to the Spider Calendar Plugin. If you are in any doubt as to what you are doing you might not want to attempt these changes but in the very least back-up your site before you try.

Step 1
Download and install the Advanced Access Manager Plugin.

Step 2
In the WP-Content\Plugins folder of your WP site find the spider-event-calendar folder. Within this folder you are going to edit the following files.

  • Calendar_functions.html.php
  • calendar_functions.php
  • preview.php
  • preview_widget.php
  • Theme_function.html.php
  • Theme_functions.php
  • widget_Themes_function.html.php
  • widget_Theme_functions.php

In each of these files locate the line If (!current_user_can('manage_options')) { and change it to If (!current_user_can('edit_posts')) {

This will allow users of Contributor level and above the ability to use the calendar plugin functionality.

Step 3
In the same spider-event-calendar Plugin folder edit the folowing file.

  • calendar.php

Locate the function call for add_menu_page (At the time of writing it is on line 465 of the file). Review the arguments supplied to this function and you will find the 'manage_options' capability check is here as well. Once again change 'manage_options' to 'edit_posts.

Repeat this change for the next 7 lines (466 through 473) which create the submenu items using the function add_submenu_page.

This will allow anyone of Contributor level and above to see the calendar menu in their dashboard admin menu bar.

Step 4
Now Use the AAM plugin to restrict those menu items which you feel are not appropriate for your contributors to have access to. i.e. change theme, uninstall etc.

If you have followed this correctly you should now find that contributors and above can use the plugin.

You can restrict or allow the plugin to a wider or narrower group by reviewing the capabilities section of the WP codex and selecting a capability appropriate to the role you want to have access. In this example I have used 'edit_posts' which is available to contributors and above, but you could use any other role that allows the level of access you want.

It is also possible to allow or restrict which roles can use the calendar and menu items using capabilities alone, I preferred to open the calendar up to anyone contributor level and above and use AAM to apply restrictions but you could do it without using AAM.

Free269 on "Remove "/category/" from the URL and fix sub categories"

$
0
0

Hi guys :)

I want to remove the "/category/" from the URL.
So instead of having: http://www.mysite.com/category/desenhos/
I will have http://www.mysite.com/desenhos/

and the next thing I will want to do is:
If I have a sub item under a category so instead of having:
http://www.mysite.com/category/subcategory
I will have
http://www.mysite.com/Unartistic/subcategory

This is how my menu looks like:
http://i57.tinypic.com/33bhkd1.jpg

I don't know how even to start changing this kinda stuff
never worked with URLs especially not with wordpress.

Thank you :)

enrico.vallicella on "wordpress publicize logout"

$
0
0

hi when i try to configurate publicize on jetpack (facebook, twitter ecc.) automatically log me out and i cant change the settings.

my site is enricoeleonora.com previous whas dodophotos.net
although it currently is not set, it remains connected to the old social network

PLEASE HELP
I need for work and it is creating me quite a few problems
Enrico.

rsepierre on "Get the paginated post link in the flow"

$
0
0

Hi,
i'm setting up my first wordpress theme for http://nouveau-document.net
For the pleasure of viewers I would like to add a feature to my website.

When an article in the flow has focus (when clicked, or focused with tabulation)I would like the url to change for the link of the post into the page, NOT the permalink. BUT ! I'm using infinite scroll meaning that I won't have the website/page/2/ in the url.

So if I'm on the homepage, I can see articles from /page/6/ but the url will still be nouveau-document.net/

I would like, when I focus an article, or scroll to it to change the url to : http://nouveau-document.net/page/x/#post-id
(with window.history.pushState()

of course i can manage to get the url, and the post-id, I miss the "page in the flow" information from a post.

This way, if the user want's to share what he's seeing, he just ctrl+c/ctrl+v the url to email, facebook, bookmarks. The url will bring him at the desired spot

If anyone has tips ?!


colinsp on "My get_results query not returning any results"

$
0
0

Anyone got any clues please? I expect I have done something stupid.

//Assign users to studies as authors
global $wpdb;
echo "Started";
$wpdb->show_errors();
// First get the profiles
$result = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE  post_type='name_profile'");
print_r ($result);
foreach ($result as $results){
$study_id = $results->id;
echo "Study ID= ". $study_id;
$study_name = $results->post_title;
echo $study_name;
/*$result1 = $wpdb->get_row("SELECT * FROM $wpdb->variants WHERE  study = $study_name");
$author = $result1->number;
$result2 = $wpdb->get_row("SELECT id FROM $wpdb->users WHERE  user_login = $author");
$author = $result2->id;
echo $author;
 $my_post = array(
      'ID'           => $study_id,
      'post_author' => $author
  );

// Update the post into the database
  wp_update_post( $my_post );*/

echo "Updated";
}

xymalf on "Forms"

$
0
0

I am currently working on a wordpress plugin. I want to create a form under setting that the user can fill with his amazon details. How do I create the setting link and form please? How do I get data from form and validate it and pass back to my front end of the PHP program? Also must user submited data be stored in a data base - how do you achieve this as every WP site has its own database and I assume password.

jdaniel on "Twitter Widget Pro - Range Dashboard Widget removal Part 2"

$
0
0

I once installed Twitter Widget Pro that comes along with a Dashboard Widget by Range (http://http//ran.ge/)

I disabled and deleted the Twitter Plugin long time ago. But I still have that Range widget on my Dashboard. How can I remove it? (It is displayed to all new users by default, which I don't want. So I don't just want "not to display it on MY dashboard individually", but delete it once and for all.)

Can anybody help me? (I read http://wordpress.org/support/topic/twitter-widget-pro-range-dashboard-widget-removal-1?replies=2, but it doesn't help if it's already installed.)

Thanks,
Daniel

Christiaan Conover on "Plugin options not appearing on options page using tabbed navigation"

$
0
0

I'm trying to set up my plugin's options page to use tabbed navigation via the Settings API, but the options themselves will not appear on the page. The tabs are visible, just not the settings fields.

Here is the code to create my options page:

/*
	===== Admin Plugin Options =====
	*/
	// Create submenu entry under the Settings menu
	function options_menu() {
		add_options_page(
			self::NAME, // Page title. This is displayed in the browser title bar.
			self::NAME, // Menu title. This is displayed in the Settings submenu.
			'manage_options', // Capability required to access the options page for this plugin
			self::ID, // Menu slug
			array( &$this, 'options_page' ) // Function to render the options page
		);
	} // End options_menu()

	// Set up options page
	function options_init() {
		/*
		Buffer Profiles
		Buffer uses profiles to store the social media accounts attached to a Buffer account. We will retrieve all
		social media profiles every time the plugin options page is loaded. This will only happen when the following
		conditions are met:
		- Plugin is fully authenticated with Buffer
		- The plugin options page is being displayed
		If the profiles are successfully retrieved, we can display the Buffer options. If not, we'll throw an error
		and no Buffer options will be shown, since we have no data from which to create them.
		*/
		if ( $this->api->is_site_authenticated() && ( isset( $_REQUEST['page'] ) && self::ID == $_REQUEST['page'] ) ) {
			// Get Buffer profiles for specified Buffer account
			$this->profile = $this->api->get_profile( $this->options['site_access_token'] );

			// If WordPress returns an error, notify the user
			if ( is_wp_error( $this->profile ) ) {
				echo '<div class="error settings-error"><p><strong>Uh oh! We had a problem getting the social media accounts tied to your Buffer account. Let\'s try again.</strong><br><em>WordPress Error: ' . $this->profile->get_error_message() . '</em></p></div>';
			}
			// If Buffer returns an error, notify the user
			elseif ( ! empty( $this->profile['code'] ) ) {
				echo '<div class="error settings-error"><p><strong>Uh oh! We had a problem getting the social media accounts tied to your Buffer account. Let\'s try again.</strong><br><em>API Error: ' . $this->profile['code'] . ' ' . $this->profile['error'] . '</em></p></div>';
			}
			// Otherwise the profile data is valid, so we can add the Buffer options to the page
			else {
				// Set defaults for any Buffer profiles not saved in plugin options
				$this->buffer_profile_defaults();

				// Set the array with list of enabled services
				$this->service = $this->services_list( $this->profile );

				// Register the settings for each service
				foreach ( $this->service as $service ) {
					register_setting(
						self::PREFIX . $service, // The namespace for plugin options fields. This must match settings_fields() used when rendering the form.
						self::PREFIX . 'options', // The name of the plugin options entry in the database.
						array( &$this, 'options_validate' ) // The callback method to validate plugin options
					);
				}

				// Call the Buffer options
				$this->buffer_options();
			}
		}

		// Register the Buffer authentication settings
		register_setting(
			self::PREFIX . 'buffer_auth', // The namespace for plugin options fields. This must match settings_fields() used when rendering the form.
			self::PREFIX . 'options', // The name of the plugin options entry in the database.
			array( &$this, 'options_validate' ) // The callback method to validate plugin options
		);

		// Load plugin options for Buffer authentication
		$this->auth_options();

		// Load scripts and stylesheets for the Options page
		add_action( 'admin_enqueue_scripts', array( &$this, 'options_scripts' ) );
	} // End options_init()

	/* Buffer Options */
	// Generate plugin options fields from profiles
	function buffer_options() {
		// Iterate through each profile
		foreach ( $this->profile as $profile ) {
			// Add a settings section for each type of social network
			add_settings_section(
				self::PREFIX . $profile['service'], // Name of the section
				null, // Title of the section, unneeded here because it's handled by the tabbed navigation
				null, // Callback for the section - unneeded for this plugin
				self::ID // Page ID for the options page
			);

			// Create a settings field to manage each social media profile
			add_settings_field(
				$profile['id'], // Field ID (use the profile ID from Buffer)
				'<img class="buffer_profile_avatar" src="' . $profile['avatar_https'] . '" alt="Avatar for ' . $profile['service'] . ' - ' . $profile['formatted_username'] . '"><span class="buffer_profile_username">' . $profile['formatted_username'] . '</span>', // Field title/label displayed to the user, includes avatar for profile (use the formatted username from Buffer)
				array( &$this, 'buffer_settings_field_callback' ), // Callback method to display the option field
				self::ID, // Page ID for the options page
				self::PREFIX . $profile['service'], // Settings section in which to display the field
				$profile // Send all the profile details to the callback method as an argument
			);
		}
	} // End buffer_options()

	// Authentication options
	function auth_options() {
		// Options section
		add_settings_section(
			self::PREFIX . 'buffer_auth', // Name of the section
			null, // Title of the section, unneeded here because it's handled by the tabbed navigation
			array( &$this, 'auth_callback' ), // Callback method to display plugin options
			self::ID // Page ID for the options page
		);

		// If the Client ID and Client Secret are not stored in the database, show the fields for those items
		if ( empty( $this->options['client_id'] ) || empty( $this->options['client_secret'] ) ) {
			// Buffer application client ID
			add_settings_field(
				'client_id', // Field ID
				'Client ID', // Field title/label, displayed to the user
				array( &$this, 'client_id_callback' ), // Callback method to display the option field
				self::ID, // Page ID for the options page
				self::PREFIX . 'buffer_auth' // Settings section in which to display the field
			);

			// Buffer application client secret
			add_settings_field(
				'client_secret', // Field ID
				'Client secret', // Field title/label, displayed to the user
				array( &$this, 'client_secret_callback' ), // Callback method to display the option field
				self::ID, // Page ID for the options page
				self::PREFIX . 'buffer_auth' // Settings section in which to display the field
			);
		}

		// Buffer access token to be used globally for the site (only show if Client ID and Client Secret are saved)
		if ( ! empty( $this->options['client_id'] ) && ! empty( $this->options['client_secret'] ) ) {
			// If no access token is saved in the database, display a static field label
			if ( empty( $this->options['site_access_token'] ) ) {
				// Add the settings field
				add_settings_field(
					'site_access_token', // Field ID
					'Connect to Buffer', // Field title/label, displayed to the user
					array( &$this, 'site_access_token_callback' ), // Callback method to display the option field
					self::ID, // Page ID for the options page
					self::PREFIX . 'buffer_auth' // Settings section in which to display the field
				);
			}
			// If it is set, provide the option to disconnect from Buffer
			else {
				// Add the settings field
				add_settings_field(
					'buffer_oauth_disconnect', // Field ID
					'Disconnect from Buffer', // Field title/label, displayed to the user
					array( &$this, 'buffer_oauth_disconnect_callback' ), // Callback method to display the option field
					self::ID, // Page ID for the options page
					self::PREFIX . 'buffer_auth' // Settings section in which to display the field
				);
			}
		}
	} // End auth_options()

	/* Plugin options callbacks */
	// Callback for dynamically generated Buffer settings fields
	// @param array $args arguments passed to the callback from the settings field
	function buffer_settings_field_callback( $args ) {
		// If this profile is enabled in plugin options, check the box
		if ( ! empty( $this->options['profiles'][$args['id']]['enabled'] ) ) {
			$checked = 'checked';
		}
		// If not, leave the box unchecked
		else {
			$checked = null;
		}

		// Create checkbox for enabling publishing to this service
		echo '<p>Enabled? <input id="' . self::PREFIX . 'options_profiles_' . $args['id'] . '_enabled" name="' . self::PREFIX . 'options[profiles][' . $args['id'] . '][enabled]" type="checkbox" ' . $checked . '></p>';

		// Create text input for post message
		echo '<p>Message <input id="' . self::PREFIX . 'options_profiles_' . $args['id'] . '_message" name="' . self::PREFIX . 'options[profiles][' . $args['id'] . '][message]" type="text" value="' . $this->options['profiles'][$args['id']]['message'] . '" size=40></p>';
	} // End buffer_settings_field_callback()
	/* End plugin options callbacks */

	// Authorization section
	function auth_callback() {
		// If client ID & secret haven't yet been saved, display this message
		if ( empty( $this->options['client_id'] ) || empty( $this->options['client_secret'] ) ) {
			// Set the callback URL. Do not encode for a URL string.
			$callbackurl = $this->api->optionsurl();

			// Display the message
			echo '<p style="color: #E30000; font-weight: bold;">In order to use this plugin, you need to <a href="https://bufferapp.com/developers/apps/create" target="_blank">register it as a Buffer application</a></p><p>It\'s easy! Once you\'ve registered the application, copy the Client ID and Client Secret from the email you receive and paste them here.</p><p><strong>Callback URL</strong>: <a href="' . $callbackurl . '">' . $callbackurl . '</a></p>';
		}
		// If they have been saved, check whether there's an access token. If not, inform the user.
		else {
			if ( empty( $this->options['site_access_token'] ) && empty( $_REQUEST['code'] ) && empty( $_REQUEST['error'] ) ) {
				echo '<div class="updated settings-error"><p><strong>You\'re almost done!</strong><br>Click the button below to authenticate this site with your Buffer account.</p></div>';
			}
		}
	} // End auth_callback()

	// Client ID
	function client_id_callback() {
		echo '<input type="text" name="' . self::PREFIX . 'options[client_id]" id="' . self::PREFIX . 'options_client_id" value="' . $this->options['client_id'] . '" size=40>';
	} // End client_id_callback()

	// Client secret
	function client_secret_callback() {
		// If client secret is saved in the database, the field is type 'password'. If not, it's type 'text'.
		if ( ! empty( $this->options['client_secret'] ) ) {
			echo '<input type="password" name="' . self::PREFIX . 'options[client_secret]" id="' . self::PREFIX . 'options_client_secret" value="' . $this->options['client_secret'] . '" size=40>';
		}
		else {
			echo '<input type="text" name="' . self::PREFIX . 'options[client_secret]" id="' . self::PREFIX . 'options_client_secret" value="' . $this->options['client_secret'] . '" size=40>';
		}
	} // End client_id_callback()

	// Access token
	function site_access_token_callback() {
		// If access token is not set, run the process to retrieve it
		if ( empty( $this->options['site_access_token'] ) ) {
			// Call the OAuth method
			$this->api->buffer_oauth_connect();
		}
	} // End client_id_callback()

	// Buffer OAuth disconnect
	function buffer_oauth_disconnect_callback() {
		// Checkbox input field
		echo '<input type="checkbox" name="' . self::PREFIX . 'options[oauth_disconnect]" id="' . self::PREFIX . 'options_oauth_disconnect" value="yes">';
		echo '<p class="description"><strong>WARNING:</strong> checking this box will remove the account credentials for the Buffer user currently associated with this plugin.</p>';
	}

	// Validate plugin options
	function options_validate( $input ) {
		// Set a local variable for the existing plugin options. This is so we don't mix up data.
		$options = $this->options;

		// If client ID and client secret have been changed from what's in the database, validate them
		if ( empty( $this->options['client_id'] ) || empty( $this->options['client_secret'] ) ) {
			// Check to make sure whether the provided values are hexadecimal
			if ( ctype_xdigit( $input['client_id'] ) && ctype_xdigit( $input['client_secret'] ) ) {
				$options['client_id'] = $input['client_id']; // Application client ID
				$options['client_secret'] = $input['client_secret']; // Application client secret
			}
			// If either one of them is not hexadecimal, throw an error
			else {
				add_settings_error (
					self::ID, // Setting to which the error applies
					'client-auth', // Identify the option throwing the error
					'Hang on a second! The client ID or client secret you entered doesn\'t match Buffer\'s format. Double-check them both, and take another crack at it.', // Error message
					'error' // The type of message it is
				);
			}
		}

		// Access token will only be saved if Client ID and Client Secret are both already saved, but no access token is saved
		if ( ! empty( $this->options['client_id'] ) && ! empty( $this->options['client_secret'] ) && empty( $this->options['site_access_token'] ) ) {
			// Make sure a value is provided for the access token
			if ( ! empty( $input['site_access_token'] ) ) {
				// Only perform the validation tasks if the value has changed from what's in the database
				if ( $input['site_access_token'] != $this->options['site_access_token'] ) {
					// Query the plugin API to validate the access token
					$apiresult = $this->api->get_user( $input['site_access_token'] );

					// If the API returns a user ID, and the user ID is hexadecimal, the access token is valid
					if ( ! empty( $apiresult['id'] ) && ctype_xdigit( $apiresult['id'] ) ) {
						$options['site_access_token'] = $input['site_access_token'];
						$options['site_user_id'] = $apiresult['id'];

						// Display a successful message on the next page load
						add_settings_error (
							self::ID, // Setting to which the message applies
							'site-access-token', // Identify the option throwing the message
							'Hooray! Your site is now fully authenticated with Buffer, and you\'re ready to go!', // Success message
							'updated' // The type of message it is
						);
					}
					// If we got an error back from Buffer, notify the user
					elseif ( ! empty( $apiresult['code'] ) ) {
						add_settings_error (
							self::ID, // Setting to which the error applies
							'site-access-token', // Identify the option throwing the error
							'Uh oh! Buffer says that something went wrong. Let\'s give it another shot!<br><em>' . $apiresult['code'] . ' ' . $apiresult['error'] . '</em>', // Error message
							'error' // The type of message it is
						);
					}
					// If the result was a WordPress error, show the error
					elseif ( is_wp_error( $apiresult ) ) {
						add_settings_error (
							self::ID, // Setting to which the error applies
							'site-access-token', // Identify the option throwing the error
							'Uh oh! WordPress had an error.<br><em>' . $apiresult->get_error_message() . '</em>', // Error message
							'error' // The type of message it is
						);
					}
				}
			}
			// If nothing is provided for the access token, throw an error
			else {
				add_settings_error (
					self::ID, // Setting to which the error applies
					'site-access-token', // Identify the option throwing the error
					'Whoops! It looks like you haven\'t yet authenticated with Buffer, and we can\'t continue until that\'s done. Let\'s try again!', // Error message
					'error' // The type of message it is
				);
			}
		}

		// If the site is fully authenticated, process the rest of the plugin options
		if ( $this->api->is_site_authenticated() ) {
			// If OAuth Disconnect is selected, remove the Buffer user credentials
			if ( ! empty( $input['oauth_disconnect'] ) ) {
				$options['site_access_token'] = null;
				$options['site_user_id'] = null;
			}
			// If OAuth Disconnect is not set, process the Buffer profile settings
			else {
				// Set local variable for 'profiles' input
				$profiles = $input['profiles'];

				// Sanitize the values of the 'enabled' checkboxes
				foreach ( $profiles as $id => $fields ) {
					// Sanitize the 'enabled' checkbox
					if ( ! empty( $fields['enabled'] ) ) {
						$profiles[$id]['enabled'] = 'on';
					}
					else {
						$profile[$id]['enabled'] = null;
					}

					// Sanitize the text input for the 'message' field
					$profiles[$id]['message'] = sanitize_text_field( $fields['message'] );
				}

				// Save profiles options
				$options['profiles'] = $profiles;
			}
		}

		// Return the validated options
		return $options;
	} // End options_validate()

	// Render options page
	function options_page() {
		// Make sure the user has the necessary privileges to manage plugin options
		if ( ! current_user_can( 'manage_options' ) ) {
			wp_die( 'Sorry, you do not have sufficient privileges to access the plugin options for ' . self::NAME . '.' );
		}
		?>

		<div class="wrap">
			<h2><?php echo self::NAME; ?></h2>

			<?php
			// Check to see if 'tab' is set, and if so get the value
			if ( ! empty( $_GET['tab'] ) ) {
				$active_tab = $_GET['tab'];
			}
			// If 'tab' is not set, default to the first service in the array
			elseif ( empty( $_GET['tab'] ) && ! empty( $this->service ) ) {
				$active_tab = $this->service[0];
			}
			// If neither 'tab' nor the service array are set, default to the Buffer Authentication tab
			else {
				$active_tab = 'buffer_auth';
			}
			?>

			<h2 class="nav-tab-wrapper">
			<?php
			// If the service array is set, set up the tabs for the services
			if ( ! empty( $this->service ) ) {
				// Iterate through each service in the array to create each tab
				foreach( $this->service as $service ) {
					?>
					<a href="?page=<?php echo self::ID; ?>&tab=<?php echo $service; ?>" class="nav-tab <?php echo $service == $active_tab ? 'nav-tab-active' : ''; ?>"><?php echo $this->apiconfig['services'][$service]['types']['profile']['name']; ?></a>
					<?php
				}
			}
			?>
				<a href="?page=<?php echo self::ID; ?>&tab=buffer_auth" class="nav-tab <?php echo 'buffer_auth' == $active_tab ? 'nav-tab-active' : ''; ?>">Buffer Authentication</a>
			</h2><!-- .nav-tab-wrapper -->

			<form action="options.php" method="post">
				<?php
				settings_fields( self::PREFIX . $active_tab ); // Retrieve the fields created for the current tab
				do_settings_sections( self::PREFIX . $active_tab ); // Display the section for the current tab

				// Show the submit button on any screen other than OAuth authorization
				if ( ! ( ! empty( $this->options['client_id'] ) && ! empty( $this->options['client_secret'] ) && empty( $this->options['site_access_token'] ) ) ) {
					submit_button(); // Form submit button generated by WordPress
				}
				?>
			</form>
		</div>
		<?php
	} // End options_page()

	// Scripts and stylesheets for Options page
	function options_scripts() {
		//Load stylesheet
		wp_enqueue_style(
			self::ID, // Handle for the script
			plugins_url( 'admin/assets/css/options.css', $this->pluginfile ), // Location of the stylesheet
			array(),
			self::VERSION
		);
	}
	/*
	===== End Admin Plugin Options =====
	*/

Here is the same code in the Github commit where it was added, in case you'd like to see it in relation to the rest of the plugin code.

What am I missing? I should note that the options page was working without issue before I added tabbed navigation, which you can see in this commit.

Any help is appreciated, I'm sure the answer it staring me in the face but I'm just not seeing it.

Howdy_McGee on "TinyMCE 4.0 - Add Classes into Format Select"

$
0
0

With the introductions of TinyMCE 4.0 comes a new, nice Format Select which has a few categories:

Headers
- Header 1 through Header 6
Inline
- Bold through Code
Blocks
- Paragraph through Pre
Alignment
- Left through Justify

What I want to do is add a Classes Menu at the bottom (below the Alignment menu) which I can stack classes in the submenu. If I use the old fashion method:

$style_formats = array(
	array(
		'title' => '.large',
		'block' => 'p',
		'classes' => 'large',
		'wrapper' => false,

	)
);
$in['style_formats'] = json_encode( $style_formats );

The above will override everything inside my formats menu. If I print out the variable $in - style_formats doesn't exist - formats on the otherhand does exist, but as a string. I tried to json_decode it but it was no use.

How do I add a "Classes" menu appeneded to the pre-existing formats?

Viewing all 8245 articles
Browse latest View live




Latest Images