public ) { continue; } $default_post_types[] = $post_type; } if ( ! empty( $default_post_types ) ) { add_option( 'lp_toggle_wpautop_settings', $default_post_types ); } } /** * Load the plugin text domain. */ public function plugins_loaded() { load_plugin_textdomain( 'toggle-wpautop', false, basename( dirname( __FILE__ ) ) . '/languages/' ); } /** * Add our settings fields to the writing page * * @access public * @return void */ public function admin_init() { register_setting( 'writing', 'lp_toggle_wpautop_settings', array( $this, 'sanitize_settings' ) ); register_setting( 'writing', 'lp_toggle_wpautop_auto' ); // Add a section for the plugin's settings on the writing page. add_settings_section( 'lp_toggle_wpautop_settings_section', __( 'Toggle wpautop', 'toggle-wpautop' ), array( $this, 'settings_section_text' ), 'writing' ); // For each post type add a settings field, excluding revisions and nav menu items. if ( $post_types = get_post_types() ) { // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found, Squiz.PHP.DisallowMultipleAssignments.Found add_settings_field( 'lp_toggle_wpautop_auto', esc_html__( 'Auto Enable', 'toggle-wpautop' ), array( $this, 'toggle_wpautop_auto_field' ), 'writing', 'lp_toggle_wpautop_settings_section' ); $show_private_post_types = apply_filters( 'lp_wpautop_show_private_pt', false ); foreach ( $post_types as $post_type ) { $post_type_object = get_post_type_object( $post_type ); if ( in_array( $post_type, array( 'revision', 'nav_menu_item', 'attachment' ), true ) || ( ! $show_private_post_types && ! $post_type_object->public ) ) { continue; } add_settings_field( 'lp_toggle_wpautop_post_types' . $post_type, $post_type_object->labels->name, array( $this, 'toggle_wpautop_field' ), 'writing', 'lp_toggle_wpautop_settings_section', array( 'slug' => $post_type_object->name, 'name' => $post_type_object->labels->name, ) ); } } } /** * Display our settings section * * @access public * @return void */ public function settings_section_text() { ?>

/> /> action ) && 'add' === $screen->action && get_option( 'lp_toggle_wpautop_auto', 0 ) ) { $checked = true; } else { $checked = get_post_meta( $post->ID, '_lp_disable_wpautop', true ); } ?>
: /> ?
ID, '_lp_disable_wpautop', true ) ) { remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' ); } else { if ( ! has_filter( 'the_content', 'wpautop' ) ) { add_filter( 'the_content', 'wpautop' ); } if ( ! has_filter( 'the_excerpt', 'wpautop' ) ) { add_filter( 'the_excerpt', 'wpautop' ); } } } /** * After we run our loop, everything should be set back to normal * * @access public * @return void */ public function loop_end() { if ( ! has_filter( 'the_content', 'wpautop' ) ) { add_filter( 'the_content', 'wpautop' ); } if ( ! has_filter( 'the_excerpt', 'wpautop' ) ) { add_filter( 'the_excerpt', 'wpautop' ); } } /** * Add a class to posts noting whether they were passed through the wpautop filter * * @param mixed $classes Array of Post Classes. * @param mixed $class Current Class. * @param int $post_id Post ID. * * @return array */ public function post_class( $classes, $class, $post_id ) { if ( get_post_meta( $post_id, '_lp_disable_wpautop', true ) ) { $classes[] = 'no-wpautop'; } else { $classes[] = 'wpautop'; } return $classes; } } } $lp_toggle_wpautop = new LP_Toggle_wpautop(); /** * Delete everything created by the plugin * * @access public * @return void */ function toggle_wpautop_uninstall() { // Delete post meta entries. delete_post_meta_by_key( '_lp_disable_wpautop' ); // Delete settings. delete_option( 'lp_toggle_wpautop_settings' ); } register_uninstall_hook( __FILE__, 'toggle_wpautop_uninstall' );