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

prashants on "Store user session using aws elastic cache (memcahe)"

$
0
0

Hi ,

i am trying to store user session over elastic cache. i am able to configure elastic cache with w3tc plugin. But when i flush the cache from the memcache(elastic cahe aws) my user still remain logged in the account.

Could somebody please help me over it.


laichejl on "WooCommerce to Authorize.net -- Not Pulling Shipping Information"

$
0
0

I'm currently running Woocommerce with Authorize.net integration on http://www.olli.com. When you go to the checkout page, it asks for billing and shipping information. However, once you place order and are transferred to the authorize.net page, the shipping information does not carry over. Is there somewhere in the plugin files that certain code needs to be edited for this?

elsnare on "Pagination problem on custom wp_query sort order"

$
0
0

Hello!

Some info:
1. I'm using a custom build wp_query to display a list of custom posts with some custom post fields. Works great.

2. I'm using the following code to sort the posts ASC/DESC depending on custom fields. Simple url GET with custom keys and values. Also works fine.

<a href="<?php echo esc_attr( add_query_arg( 'order', 'city_desc' ) ); ?>"></a>  

if (isset($_GET['order'])) {
$sort= $_GET['order'];

 if($sort == 'city_desc'){
                  $args['order'] = 'DESC'; $args['meta_key'] = 'city';
				  }

The problem
When I enable pagination and sort the results - everything seems fine at first: the order is ok, the posts get split ect. But when I enter the second page of results something strange happens.

Let's say I have 3 posts and a custom field 'price':

POST A - 100
POST B - 200
POST C - 300
Posts per page is set to 2.

Pagination page #1 after sorting DESC I get:

POST C - 300
POST B - 200

But on page #2 I get:

POST C - 300
and that's it

So it seems there is a conflict between the pagination function which returns a given number of posts (1 in this example) on the 2nd page, but uses the sorting, resulting in a duplicate of POST C.

Here are the URL for those pages:

For sorted results:
list_page/?order=price_desc

For page #2

some_page/page/2/?order=price_desc%2F

I'm using a plugin to do the pagination.

Any thoughts? :)

peter-hamilton on "Plugin jQuery and CSS Overload?"

$
0
0

Good topic, I am also wondering the same.

Running BBpress and about 6 plugins and site is very slow.

Google pagespeed gives me 64 points and lots of issues.

Looking forward to an answer.
P.H.

xymalf on "creating a skeleton plugin framework."

$
0
0

I would like to create an menu for a plugin I am developing. So far I have followed examples in books but have got nothing to work. I just want a simple tag on the wordpress dashboard with Settings and Application below it - can anybody point me in the right direction.

Sascha_77 on "Bigger description field in Nextgen Gallery Uploader? Solution is here. :)"

$
0
0

Hi folx.

I figured out how to expand (and word-wrap) the very tiny description filed in the nextgen gallery uploader.

Open the file:
wp-content/plugins/nextgen-public-uploader/npu-upload.php

Find the Line:

$strOutput .= "\n\t<input type=\"textarea\" name=\"" . esc_attr( $name ) . "\" id=\"" . esc_attr( $name ) . "\"/>";

and replace it with this:

$strOutput .= "\n\t<textarea type=\"textarea\" style=\"height:150px;width:680px\" name=\"" . esc_attr( $name ) . "\" id=\"" . esc_attr( $name ) . "\"/></textarea>";

Now you have a resizable Text Field. :D You can change or add styles within "style" to your needs. For my needs height and width is enough.

http://s7.directupload.net/images/131227/2oqa6cwl.png

otti.steinhauer on "Detect Browser back-button"

$
0
0

Hello,
as far as I have got much help on this forum I will aks again my newest question.
In my new plugin I am programming a form in four steps. After the lat step evrything is finished and the user must not go back to the form. Everything is OK with the back-button on the site, but not with the back button of the browser.
So first I have to detect when the browser-back button is clicked and in this case either to enable this button or redirect to another page.
How can I test the Broser-buttons?
My plugin uses php and javascript.

Thanks

Ottilie

Luke Janicke on "'image' shortcode?"

$
0
0

I am writing a custom image shortcode. I would like to use the shortcode [image]. It doesn’t seem to be an existing shortcode. It isn’t defined in the core WordPress file where (for example) the [gallery] shortcode is defined.

However, when I implement and use the [image] shortcode, all the images are moved to the top of my post, before all the text content.

Here’s some raw blog text…

A friend of mine, knowing that I often went jogging, had forwarded me a link for an upcoming event out on the Inner-Mongolian grasslands and thought I might be interested. Do bears do number-2s in the forest? Yes, I was interested. I was extremely keen indeed.

[image id="372"]

A couple of other colleagues showed interest, and before we knew it, we had booked time off from work, signed up and paid our 100RMB deposits for a 10km cross-country race out in the grasslands for 6-months later.

The paragraphs and images go on like that. However, when the post is viewed, all the images are moved to the top, before all the text.

WTF?

Anyone know why?


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.

Christiaan Conover on "Tabbed navigation for plugin options using same row in database for all?"

$
0
0

I'm trying to use WordPress' native tabbed navigation on my plugin's options page, but I'm having trouble. I've managed to get the options to display, though it displays every plugin option on every tab. I also get the error message ERROR: options page not found whenever I try to save settings.

I think I've traced this to the fact that I'm trying to use the same row in the database for all plugin options. The reason for this is that most of the options fields are dynamically generated from a remote API call, so the tabs may not be the same across all installations of the plugin. Therefore, I don't want to predefine database rows for each tab, in case certain tabs are not in use, or tabs are added or removed based on the API response after plugin installation.

Is it possible to use a single row in the database for all plugin options in conjunction with WordPress' tabbed navigation?

Here's the relevant block of code in the commit containing it. I've linked to it because it contains references to methods and properties elsewhere in plugin code that may be relevant for context.

John Bee on "{Roles & capabilities} how can i modifie capabilities with phpmyadmin ?"

$
0
0

Hello,

After some troubles with a plug in, so i want to restore some capabilities to admin role. But unfortunately, i can't access to wp-admin panel.

So can you tell me :
- If i can modifie capabilities using phpmyadmin
- what are the differents tables to modified
- the process to modified (delete or add) capabilities.

Thank you for helping,

xennex81 on "Getting rid of default category"

$
0
0

I am not very happy with this "default category requirement" thing.

It is easy to disrupt it but there could be a lot of places where it hides.

But it seems easy enough to get rid of it. I've just set the option in the table to 0 and removed the form elements from /wp-admin/options-writing.php.

I don't think it will bug me any more. It seems to be treated like it is some essential design principle or feature or necessity but that is hardly the case. Posts that get added without category just don't end up in the taxonomy relations table. There might be some code that does a join between the posts and the taxonomy relations, but it doesn't seem like Wordpress' own code is dependent on that. Only my own provisionary code did such a thing.

Feels much better. I modified the "delete category" text too. Only harmony now. I just absolutely love Wordpress because it is such clean code and so very easy to modify. I'm not even backing these files up or keeping a changelog if some minor automatic update replaces a file I'm cool with that.

So thank you all for this great product and this amazing hacks forum and the only thing I am going to remove now is this hypocritical "Thank you for creating with WordPress." line that thinks it is smart enough to have a place on my computer.

djPaulWall on "Adding Subdomain to a single page"

rahmatawaludin on "How revision works under the hood?"

RikkivonTikki on "Changing UI language for guests"

$
0
0

Hi guys!
I'm looking for a basic trick. I want to simple basic switcher for guests. I was looking for solution but I haven't find any tips for me.

I need function for changing Wordpress interface language and saving a information about choice in cookie. I'm using only two language in my project.

Do you know how to make it?

Or maybe you can help me with this issue: http://wordpress.org/support/topic/the-same-page-for-several-language ?

Much thanks and regards


emanradin on "Using Regex code to add code before each image"

$
0
0

I've been trying to solve this issue for quite a while with no luck. I'm not very good with programming but still trying to have a crack.

My setup is I've enabled users to post topics frontend (just like this form) but with the "img" quicktag enabled. So, users can insert an image link within the post.

My ultimate goal is to add a link to each image and the href linking to the images src.

So eg. my current output for images is <img src="link-to-image.jpg">

But what I'd like to achieve is <a href="link-to-image.jpg"><img src="link-to-image.jpg"></a>

My only luck so far was by using the regex code found here: http://wordpress.org/support/topic/add-code-before-each-image?replies=6

I've tried many different ways including functions like: image_send_to_editor, get_image_tag, $replacement, $pattern but nothing so far has made any changes to the image markup like it has with the regex code above.

I've updated this section of the code to add a span before image linking to the post thumbnail attachment, but how can i achieve to link each image to its full src within the post using this regex code:

// If we get any hits then put the code before and after the img tags
if ( $mh_matches ) {;
        for ( $mh_count = 0; $mh_count < count( $mh_matches[0] ); $mh_count++ )
                {
                // Old img tag
                $mh_old = $mh_matches[0][$mh_count];

                // Get the img URL, it's needed for the button code
                $mh_img_url = $mh_matches[1][$mh_count];

                // Put together the pinterest code to place before the img tag
                $mh_pinterest_code = '<span class="test"><a href="' . ( wp_get_attachment_url( get_post_thumbnail_id() ) ) . '">';

                // Replace before the img tag in the new string
                $mh_new = preg_replace( '/^/' , $mh_pinterest_code , $mh_old );
                // After the img tag
                $mh_new = preg_replace( '/$/' , '</a></span>' , $mh_new );

                // make the substitution
                $content = str_replace( $mh_old, $mh_new , $content );
                }
        }
return $content;
}

Full code here: http://pastebin.com/PJ9S4zWe

Thanks

SDM36 on "WP Query date_query problem"

$
0
0

Hiya,

Basically I'm trying to order a bunch of posts by season; 'spring', 'summer' and what have you.

It occurred to me that the easiest way of achieving this was to run four new WP_Query's using date query for each season.

To that end I got this far:

<?php $args = array(
		'posts_per_page' => -1,
		'cat'	=> 19,
		'date_query' => array(
					array(
						'month' => 1,
						'month' => 2,
						'month' => 3
						 ),
				'relation' => 'OR'
				 )
			); 	?>
<?php $spring = new WP_Query($args); ?></p>
<p><?php while ( $spring->have_posts() ) : $spring->the_post(); ?>
<?php print_r($post); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>

Yet that doesn't return anything.
It's definitely to do with the date_query array as when I remove it all posts come out fine.

I've followed the advice and format as per the codex and am left scratching the old head.

Anyone able to give me a quick pointer please?

somtam on "Save loading time with admin_init"

$
0
0

Hello everybody,
I was wondering about this.
To save loading time, do I have to insert inside admin_init hook all the hook about admin pages.
As an example, filter like "manage_edit-post_columns" or action like "manage_pages_custom_column".

thanks for support!

cabrailsford on "How to add (and save) checkbox to custom meta box"

$
0
0

I have input the following code to create a custom meta box for a site I'm building. However, I can't seem to get the checkbox to save after clicking "Publish" or "Update". I've tried several different variations of code from different sources on how to tackle it, but they seem to not match up with what I'm doing, and therefore have no effect. If anyone can assist in telling me what to add/change to get it to work, I'd greatly appreciate it!

// The Contact Metabox
	function cg_contact() {
    	global $post;

    // Noncename needed to verify where the data originated
    echo '<input type="hidden" name="contactmeta_noncename" id="contactmeta_noncename" value="' .
    	wp_create_nonce( plugin_basename(__FILE__) ) . '" />';

	// Get the contact data if its already been entered
    $phone1 = get_post_meta($post->ID, '_phone1', true);
	$phone2 = get_post_meta($post->ID, '_phone2', true);
	$fax = get_post_meta($post->ID, '_fax', true);
	$emailaddr = get_post_meta($post->ID, '_emailaddr', true);
	$websiteaddr = get_post_meta($post->ID, '_websiteaddr', true);
	$directlink = get_post_meta($post->ID, '_directlink', true);
    // Echo out the field ?>
    <table width="100%">
    	<tr>
        	<td style="padding-right:10px;">
			<?php echo '<p>Phone 1:</p>';
			echo '<input type="text" name="_phone1" value="' . $phone1  . '" class="widefat" />';?>
            </td>
            <td style="padding-right:10px;">
			<?php echo '<p>Phone 2:</p>';
			echo '<input type="text" name="_phone2" value="' . $phone2  . '" class="widefat" />';?>
            </td>
            <td>
			<?php echo '<p>Fax:</p>';
			echo '<input type="text" name="_fax" value="' . $fax  . '" class="widefat" />';?>
            </td>
        </tr>
        <tr>
        	<td style="padding-right:10px;">
            <?php echo '<p>Email Address:</p>';
			echo '<input type="text" name="_emailaddr" value="' . $emailaddr  . '" class="widefat" />';?>
            </td>
            <td style="padding-right:10px;">
            <?php echo '<p>Website:</p>';
			echo '<input type="text" name="_websiteaddr" value="' . $websiteaddr  . '" class="widefat" />';?>
            </td>
            <td>
            <?php echo '<p>Direct Link?</p>';
			echo '<input type="checkbox" name="_directlink" class="widefat"'. checked( $check, 'on' ). '/>';?>
            </td>
        </tr>
    </table>
            <?php
}

	// Save the Contact Metabox Data
	function cg_save_contact_meta($post_id, $post) {
    // verify this came from the our screen and with proper authorization,
    // because save_post can be triggered at other times
    if ( !wp_verify_nonce( $_POST['contactmeta_noncename'], plugin_basename(__FILE__) )) {
    return $post->ID;
    }
    // Is the user allowed to edit the post or page?
    if ( !current_user_can( 'edit_post', $post->ID ))
        return $post->ID;
    // OK, we're authenticated: we need to find and save the data
    // We'll put it into an array to make it easier to loop though.
    $contact_meta['_phone1'] = $_POST['_phone1'];
	$contact_meta['_phone2'] = $_POST['_phone2'];
	$contact_meta['_fax'] = $_POST['_fax'];
	$contact_meta['_emailaddr'] = $_POST['_emailaddr'];
	$contact_meta['_websiteaddr'] = $_POST['_websiteaddr'];
	$contact_meta['_directlink'] = $_POST['_directlink'];
    // Add values of $contact_meta as custom fields
    foreach ($contact_meta as $key => $value) { // Cycle through the $events_meta array!
        if( $post->post_type == 'revision' ) return; // Don't store custom data twice
        $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
        if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
            update_post_meta($post->ID, $key, $value);
        } else { // If the custom field doesn't have a value
            add_post_meta($post->ID, $key, $value);
        }
        if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
    }
}
add_action('save_post', 'cg_save_contact_meta', 1, 2); // save the custom fields

djones8520 on "Calling a php file within a php file"

$
0
0

I'm having trouble calling a php file from within a php file. What I'm trying to do is create a shortcode that will call a php file that will display some content on a page.

The shortcode part works, because I have displayed something simple to test that it's working. I have used include in the past, but that was for when I wanted to use a function from another file. I want the whole file to run, not a function.

I humored myself and tried include("file.php") and include file.php and neither works. From what I've read the exec command should work, but that hasn't worked for me either.

exec('php file.php') is an example of what I've tried.

Thanks for any suggestions.

Viewing all 8245 articles
Browse latest View live


Latest Images