Tag Info

Hot answers tagged

21

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 ...


19

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 ...


16

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

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, ...


14

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 ...


13

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); ...


13

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. ...


11

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 ...


8

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(), ); ...


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' => ...


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

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 ...


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 ) { ...


4

Known issue The only thing were you shouldn't use the class WP_List_Table without checking if it is already in use, is inside a meta box. Reason Using it would break the columns of one of the meta boxes as there's only one filter to setup the screen columns per screen. Filters manage_{$screen->id}_columns inside get_column_headers() ...


4

Something like this works: $url = 'https://xxx'; $body = array( 'auth_token' => 'xxxxxx', 'list_id' => 'xxxxx, 'name' => 'Office', 'campaign_id' => 'xxxxx', ); $response = wp_remote_post($url, array( 'body'=>$body, 'sslverify' => false // this is needed if your server doesn't have the latest CA certificate lists ...


4

WordPpress platform provides XML-RPC support which you can use to maintain your WP site. You also enable to extend functionality of build in xml-rpc methods to use it for your needs.


4

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 ...


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: ...


4

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 ...


3

Hi @James: If you have the post ID of your newly created post (the $created variable from your question) you use the wp_set_object_terms() function, for example: wp_add_post_tags($created,'My First Tag'); wp_add_post_tags($created,'My Second Tag'); wp_add_post_tags($created,'My Third Tag');


3

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 ...


3

I haven't used Socialite before today, so I did a quick install to see if I could reproduce the problem and ... wow ... The system is definitely broken. Facebook requires you to partially host your application on your own server. You set up some integration so you can use its API, but most of the work actually happens off-site. With other ...


3

The do_settings_section() function call needs to correspond to the $optiongroup argument you pass to register_setting(). To see how all of the myriad functions fit together, see page 10 of my tutorial. It does get fairly confusing trying to follow how the various functions string together. EDIT: You do appear to be using the option group properly. Can you ...


3

I know it's been a while, but if anyone else stumbles on this, I found a WordPress hook specifically for modifying HTTP headers. The hook is wp_headers and it's called in the wp class. The first argument passed is an array of headers with the header name as the key. The second argument is a reference to the wp class object.



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