Hot answers tagged

6

It depends on how you are going to use the stored data. If you want to run complex queries against the values, use a custom table with indexes optimized for those queries. If you will always just fetch all the values for a given object, create a non-public custom post type, and store the data as post meta. Do not store the data in a serialized string, ...


4

Where to store plugin settings fields? Options table FTW. It's cached and easy to do CRUD. Settings API or Options API? Basically, you can use Options API without Settings API but you cannot use Settings API without Options API. Even when you just need to add some fields to a existing WordPress page, you still need get_option() to retrieve data for ...


3

This is actually not that hard, but you will have to excuse me for keeping it high level because this is just a stupid thing to do as all things which are security by obscurity. All you need to do is write your WPDB driver, which inherits the WPDB class. Place it in /wp-content/db.php file and make sure to initialize the global $wpdb object with your class. ...


3

You can use following: update_option( 'show_on_front', 'page' ); update_option( 'page_on_front', '0' ); I hope this helps.


2

If you want a quick programmatic way of looping through everything you have in the cron row inside wp_options and you have access to the site's database directly (either in a local development environment or on a webhost), you can run something like this via the command line: mysql $YOUR_DB_NAME -e "SELECT option_value FROM wp_options WHERE option_name='...


2

Given that you are dealing with email, I'd run wp_kses() with a very limited $allowed_html array similar to this sample from the Codex: array( 'a' => array( 'href' => array(), 'title' => array() ), 'br' => array(), 'em' => array(), 'strong' => array(), ); HTML rendering is even more squirrelly in email ...


2

$values = get_option( 'option_name') // Create array from string $values_array = explode( PHP_EOL, $values ); sort( $values_array ); // Create string from sorted array $sorted_values = implode( PHP_EOL, $values_array ); Read more about the sort function


2

If we check how the wp_options table is created (in 4.4) from the schema.php file, we will find the following: CREATE TABLE $wpdb->options ( option_id bigint(20) unsigned NOT NULL auto_increment, option_name varchar(191) NOT NULL default '', option_value longtext NOT NULL, autoload varchar(20) NOT NULL default 'yes', PRIMARY KEY (option_id), ...


1

Yes this is actually the same as point 1, just without the helpers Now this depends on how you want to use your setting. The instinct is that at 99% of the cases this will just add unneeded complexity to your code and hurt performance. As long as we are talking about setting and not content or widgets, the settings API is what you should use. It takes ...


1

You could use wp_parse_id_list() to sanitize your comma seperated list of post IDs. It's defined as: function wp_parse_id_list( $list ) { if ( !is_array($list) ) $list = preg_split('/[\s,]+/', $list); return array_unique(array_map('absint', $list)); } where we can see that it returns unique array values as well. Note that absint() is ...


1

You have a free wordpress plugin made for that: Custom Post Type Permalinks Let us know if it is convenient


1

Your problem is that serialized strings contains escape slashes that are not evaluated as such, because the wrapping quote is a single quote. You are using: $v = 'a:2:{i:0;b:0;s:8:\"auto_add\";a:0:{}}'; // wrong You have to use either $v = "a:2:{i:0;b:0;s:8:\"auto_add\";a:0:{}}"; // ok or $v = 'a:2:{i:0;b:0;s:8:"auto_add";a:0:{}}'; // ok By the ...


1

That entry is a PHP serialized array. The serialize method takes an array and stores it's value as a string so it can be stored elsewhere - like a database. In the above example, the "s:" entries stand for "string:". With a serialized array, each element's data type is represented by a letter (a, s, o, etc) followed by a colon, then an optional length, and ...


1

When your Cron array gets stuffed with more than one task, then there's a high chance, that you either forgot to check if there's already an unfinished task in the queue, or you have the config wrong. The config array gets used to ID a task in the queue. Meaning if you for e.g. have a typo or some other difference between wp_next_schedule() checks and ...


1

If you import the database on your phpmyadmin. It has an option while importing sql files. Don't use AUTO_INCREMENT for null tables or zero rows. This option just above the go button. Read this checkbox and mark it based on your choice. Than import your database. It won't be the problem. The option_ID is an primary key and it's AUTO_INCREMENT. If ...


1

I faced same type of issue when I imported my database via phpmyadmin. I think, if you have a database backup, then you can try another re-import operation vaia phpmyadmin. That worked for me, but not sure if that works for you.



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