Tag Info

Hot answers tagged

23

I might be misunderstanding you, but why not use wp_create_nav_menu()? E.g., this is what I do to create a custom BuddyPress menu when I detect BP as active: $menuname = $lblg_themename . ' BuddyPress Menu'; $bpmenulocation = 'lblgbpmenu'; // Does the menu exist already? $menu_exists = wp_get_nav_menu_object( $menuname ); // If it doesn't exist, let's ...


21

There are two types of rewrite rules in WordPress: internal rules (stored in the database and parsed by WP::parse_request()), and external rules (stored in .htaccess and parsed by Apache). You can choose either way, depending on how much of WordPress you need in your called file. External Rules: The external rule is the easiest to set up and to follow. It ...


20

Hi @Sruly: You've pretty much answered your own question, but I'll elaborate a bit. Action Hooks Actions Hooks are intended for use when WordPress core or some plugin or theme is giving you the opportunity to insert your code at a certain point and do one or more of the following: Use echo to inject some HTML or other content into the response buffer, ...


19

There is a global variable in wp-admin called $pagenow which holds name of the current page, ie edit.php, post.php, etc. You can also check the $_GET request to narrow your location down further, for example: global $pagenow; if (( $pagenow == 'post.php' ) && ($_GET['post_type'] == 'page')) { // editing a page } if ($pagenow == ...


15

if you look at the do_settings_sections function more specifically the line 1164 where the callback function is being executed : call_user_func($section['callback'], $section); you can see that the $section array is being passed to the callback function, so you can identify the callback by the $section['id'] hope this make since. Update here is an ...


14

The API you offer in a plugin or a theme depends on the logic of that specific code. There is probably no guide that applies to all situations. I am a contributor for multiple plugins with APIs, and what I have learned so far is: Do not offer an API until you really know how people use your code. Release the first two or three versions without any API. ...


14

WordPress expects the $_SERVER variables to be setup as if it were a normal web request. Also, I would suggest loading wp-load.php instead of wp-blog-header.php since you probably don't need the WP class or the template loader to run. Here is how I normally start any scripts I need to interact with WP from command line: define('DOING_AJAX', true); ...


12

I think the best option is an endpoint. You get all the data as a simple string, so you can decide how it will be parsed, and you don’t have to worry about collisions with other rewrite rules. One thing I learned about endpoints: keep the main work as abstract as possible, fix the glitches in WordPress’ API in a data agnostic way. I would separate the ...


9

There's a few bits here that apply, but the short of it is this code in customize-preview.js: this.body.on( 'click.preview', 'a', function( event ) { event.preventDefault(); self.send( 'scroll', 0 ); self.send( 'url', $(this).prop('href') ); }); The event.preventDefault prevents the links from actually working. The following code then sends a ...


9

The way to do this is to use the 'admin_enqueue_scripts' hook to en-queue the files you need. This hook will get passed a $hook_suffix that relates to the current page that is loaded: function my_admin_enqueue($hook_suffix) { if($hook_suffix == 'appearance_page_theme-options') { wp_enqueue_script('my-theme-settings', ...


8

This worked for me. I never ever touch the rewrite API, but am always up to push myself in new directions. The following worked on my test server for 3.0 located in a sub folder of localhost. I don't for see any issue if WordPress is installed in web root. Just drop this code in a plugin and upload the file named "taco-kittens.php" directly in the plugin ...


7

If you are using PHP 5.2+ you're best bet is to just make a PHP array or object and use json_encode(). UPDATED: $cats = get_categories(); $output = array('categories' => array()); foreach ($cats as $cat) { $cat_output = array( 'cat_id' => $cat->term_id, 'cat_name' => $cat->name, 'posts' => array(), ); ...


7

This question is going to get some opinion based answers, but well, I'll give it a try. There are a couple of reasons why someone might've told you that, it would be great to know the context also. Upto version 3.4 or 3.5, that function only worked when the parameter was a var, that might be one of the reasons why someone told you that. I, myself, don't ...


7

For starters let's dive into what is 5 really. It is the post's ID. But what is ID in turn? It is value in the MySQL table row which identifies the specific post record. Issues with using IDs So first there are some conceptual problems with it. It's not content. It's not something user creates, manipulates, or (most of the time) aware of. WP is (by design) ...


6

First off: This Theme is so doing it wrong. One should not simply stuff plain calls in functions.php files. Those should be wrapped and hook. Best to after_setup_theme(). You could btw try the same hook.


6

I tried for a bit and could not get this to work perfectly, but it's close, it's hard to extend with the <form> for the popup styles being hardcoded, thought possible with more work. To get started you can: Enqueue the link popup javascript and styles, the main .js file is wp-includes/wplink.js. Depending on where you loading this you might need to ...


6

Cross-site Scripting Issues You cannot transfer WP auth cookies between domains. You also don't want to store plaintext passwords for logging into another WP installation programmatically. So, you'll have to have users log into WordPress, and then access their login status via an API endpoint from the third-party site. This lets WordPress handle all the ...


6

As a complement to ZaMoose's anwser, here's how you would create a "Page-type" menu item (not a "Custom" one): wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => 'About', 'menu-item-object' => 'page', 'menu-item-object-id' => ...


6

wp_get_active_and_valid_plugins() get_plugins() and get_option('active_plugins')


5

There multiple WordPress Apis for getting a list of plugins like OTP listed in his answer. get_plugins() :Check the plugins directory and retrieve all plugin files with plugin data. Returns an array. Note: Only works on the admin side Example: function list_the_plugins() { $plugins = get_plugins(); foreach ( $plugins as $plugin ) { ...


5

wp_localize_script() now uses json_encode() which means a multidimensional array will now work for the passed data. And, HTML entity decoding only applies to the first level of the array. Better is an way to use json and default js possibilities from WP. At first, i add the options from the database via script and json_encode to wp header: add_action( ...


5

I'm a little confused by your question, can you not simply use wp_enqueue_style, which you actually wrote into this threads heading(not sure if you know the function exists or not). wp_enqueue_style works in the same way as the wp_enqueue_script counterpart, but of course as you'd expect, enqueues stylesheets.. Here's a list of the enqueues i was able to ...


5

WordPress features a very rich XML-RPC interface that you can work with from external applications. It provides you access to most of the functionality you'd have directly in the admin - write posts, edit posts, edit comments, create/edit categories, manage site options, upload files, etc. As a matter of fact, certain third-party applications are already ...


5

Let me apologize for the initial question I had about your motives. I see a lot of "how can I remotely retrieve all posts from another blog" questions and immediately assume there is nefarious intent because, 9 times out of 10, there is. That said, your purposes seem very straight-forward and respectable. Currently, there is no way to "chunk" the XML ...


5

This does not answer the question in specific, but those are some resources regarding the question (as a community wiki, feel free to add stuff). Blog Articles and Discussions What Data Does WordPress Send Back to the Mothership (Lynne Pope; 14 Dec 2009) Is WordPress Spyware? (Jeff Chandler; 10 Dec 2009) WordPress Tavern Forums: WordPress and phone home ...


4

I came up with a function that does the job for now : /** * Creates a translation of a post (to be used with WPML) * * @param int $post_id The ID of the post to be translated. * @param string $post_type The post type of the post to be transaled (ie. 'post', 'page', 'custom type', etc.). * @param string $lang The language of the translated post (ie ...


4

Yes, it's wp_insert_post().


4

To offer an alternative method/approach to the above question. // When you are viewing the users list or your editing another user's profile add_action( 'admin_print_scripts-users.php', 'your_enqueue_callback' ); // When you are editing your own profile add_action( 'admin_print_scripts-profile.php', 'your_enqueue_callback' ); function ...


4

Hmmm, can't remember or find fitting function either. There is wp_set_object_terms() that is used in multiple wrappers like wp_set_post_categories(). It can overwrite categories for a post. So you can get post categories, check for unwanted one and write it back excluding unwanted in that case.


4

This is why: http://plugins.trac.wordpress.org/browser/stats/tags/1.7.2/stats.php#L685 The deactivation hook deletes your database information. I'm guessing you're manually deactivating the plugin, updating, and then re-activating? If so, that runs the deactivation hook. Fortunately, that's not from the latest version. This is: ...



Only top voted, non community-wiki answers of a minimum length are eligible