Articles of options

The best place of the code for creating a robots.txt file

I’m using the Option-Tree framework for the options of my theme. Now I want to add the option to create and edit the robots.txt file. First, I have the function to get the content of the file or create it with a default content; is this: function get_robots($path) { $robots_file = $path . DIRECTORY_SEPARATOR . […]

'delete_option()' only deleting the value, not the key/value pair

Recently a plugin I am developing begun throwing up an error whenever I deleted the plugin options (restored them to default). I’m using the Settings API within the plugin in question, and on another page I am checking the settings assigned to those options – $login_settings = get_option(‘fgw_login’, array()); Upon activation and after I save […]

wp_login_url not working correctly

I’m working on a project where I need to add a custom link to admin menu, and I’m using the following code for it: $login_url = wp_login_url(); add_options_page(‘Login’, ‘Login Page’, ‘manage_options’, ‘loop.php?url=’.esc_url($login_url).”); Here’s a thing. The above code is adding following URL to menu: Instead of: What’s different? It’s generating the URL with […]

Checked() function on a multidimensional array

I am generating checkboxes dynamically on one of the option pages. This the code that I’m using to create multiple checkboxes: <?php foreach($shopCategories as $shopCategory) { ?> <input type=”checkbox” value=”<?php echo $shopCategory->term_id; ?>” name=”term_meta[ss_aff_categories][]” <?php checked($term_meta[‘ss_aff_categories’], $shopCategory->term_id, true) ?>> <?php echo $shopCategory->name; ?><br/> <?php } ?> The problem is that with thechecked() function in place […]

Every time I save my plugin options it erases another plugin options

I created two plugins, when I save one settings it completely erases the settings from the other one, and it also happens the other way round. I really don’t understand what the issue might be about since they don’t share the same general configuration: one plugin options are saved in pl_popup_options and the other in […]

Theme options are they necessary

So I have decided to use wordpress for a site. But just as I begun I realized that I might need options. Things as simple as logo, favicon and possibly some parallax settings. Is it necessary to have options or can I set the logo by just getting the uploads/images path and setting it to […]

Including a custom options page causes “Pages” to disappear from dashboard menu

I’ve created a custom options page and referenced it through my functions.php file. When i do this, the Pages option is removed from the WP dashboard, almost as if overwritten by the new options page. The pages continue to exist, and I can navigate directly to the new page editor, but I cannot access it […]

Options page: values don't show up in dashboard

Following this tutorial (same code as that one) I created an options page that works well, I can retrieve option values from my templates. However when visting the option page in the dashboard, the fields remain empty although I’ve set their default value if they have one. Here’s my code: add_action(‘admin_menu’, ‘add_global_custom_options’); function add_global_custom_options() { […]

Adding option values as an array using a multi selectable select box

I have a plugin I’m developing. As part of its functionality I need to set up an option group and specify an option var for that group: function swcs_settings() { register_setting( ‘swcs-settings-group’, ‘swcs_postpage_id’ ); } add_action( ‘admin_init’, ‘swcs_settings’ ); Where swcs_postpage_idis the name of my variable. I am using this variable in a <select> box […]

Storing product price data in the database

I am writing a WordPress plugin to store product data that is pulled from the Amazon Affiliates API. My goal is to have an admin page where I can add new products and view/edit/remove existing products. Essentially I will assign each product a custom slug such as “amazon-miter-saw-blade”, then I can use a shortcode such […]