how to set default value for checkbox in wordpress

I think the problem might could be the logic with using checked… <input type=”checkbox” name=”aps_display_post_title” value=”yes” <?php if ($aps_display_post_title != ‘no’) {echo ‘checked’;} ?> /> …on the other hand then running sanitize_text_field on the checkbox value might also be causing the problem. Instead you might want to break the logic down differently so it is … Read more

How to get all existing post types

Thanks to @mmm The solution in this case is pretty simple. Just pass an empty $args array. Then it neglects the default ‘_builtin’ Example $get_post_types = get_post_types( $args = array(), $output, $operator ); return $get_post_types;

Add a Custom Permalink option in the Permalink Admin Screen?

To hook your custom plugin settings into the Permalink settings, use the following: add_action(‘admin_init’, ‘wpse_237141_custom_permalink_section’); function wpse_237141_custom_permalink_section() { add_settings_section( ‘your_custom_id’, // ID ‘Your Plugin Settings’, // Section title ‘your_callback’, // Callback for your function ‘permalink’ // Location (Settings > Permalinks) ); } You’ll need to fill in the blanks to display your own custom functions, … Read more

OOP: Display warning and deactivate the plugin if PHP version is less than 5.4

Here’s my bare-bones template that I use when creating a plugin with OOP. Feel free to modify to your liking. Template if ( !defined( ‘ABSPATH’ ) ) exit; // Exit if accessed directly if ( !class_exists( ‘MyPluginName’ ) ) { class MyPluginName { public function __construct() { // Call your actions/filters here add_action( ‘tag’, array( … Read more

Activation hook not creating table

The table name needs to be in quotes on the line where you’re checking if it exists. I tested it, and after that was fixed, the table was successfully created. Here is the full code: function mm_booking_activate() { global $wpdb; $mm_booking_table_name = $wpdb->prefix . “mm_booking”; $mm_booking_db_version = ‘1.0’; $charset_collate = $wpdb->get_charset_collate(); if ( $wpdb->get_var( “SHOW … Read more

WordPress Admin Post Type Table Class Filter Hook

The function get_post_class() is used to generate these classes. You can filter post_class to change the output. Example is_admin() && add_filter( ‘post_class’, function( $classes, $class, $post_id ) { $post = get_post( $post_id ); // Decide whether to add a class or not … $classes[] = ‘my-custom-class’; return $classes; }, 10, 3 );

Adding Automatically To In WordPress Using Filter Referencing?

You can filter the_content and use preg_replace() to look for instances of <table></table> and then surround them with your <div>. add_action( ‘the_content’, ‘wpse_260756_the_content’, 10, 1 ); function wpse_260756_the_content( $content ) { $pattern = “/<table(.*?)>(.*?)<\/table>/i”; $replacement=”<div class=”table-responsive”><table$1>$2</table></div>”; return preg_replace( $pattern, $replacement, $content ); }