Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Settings UI #66

Merged
merged 13 commits into from
Apr 7, 2023
Merged
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@
},
"require-dev": {
"phpunit/phpunit": "~7.5.0",
"10up/phpcs-composer": "dev-master"
"10up/phpcs-composer": "dev-master",
"yoast/phpunit-polyfills": "^1.0"
},
"scripts": {
"lint": "phpcs .",
"lint-fix": "phpcbf .",
"test": "phpunit",
"setup-local-tests": "bash bin/install-wp-tests.sh convert_to_blocks_test root password mysql trunk"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
65 changes: 63 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
convert_to_blocks_define( 'CONVERT_TO_BLOCKS_VERSION', $plugin_version );
convert_to_blocks_define( 'CONVERT_TO_BLOCKS_DIR', plugin_dir_path( __FILE__ ) );
convert_to_blocks_define( 'CONVERT_TO_BLOCKS_URL', plugin_dir_url( __FILE__ ) );
convert_to_blocks_define( 'CONVERT_TO_BLOCKS_SLUG', 'convert-to-blocks' );
convert_to_blocks_define( 'CONVERT_TO_BLOCKS_DEFAULT_POST_TYPES', [ 'post', 'page' ] );

/* Labels */

Expand Down
25 changes: 21 additions & 4 deletions includes/ConvertToBlocks/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function init() {
$this->register_objects(
[
new RESTSupport(),
new Settings(),
]
);
}
Expand Down Expand Up @@ -182,14 +183,30 @@ public function init_locale() {
* @return bool
*/
public function post_type_supports_convert_to_blocks( $post_type ) {
$supports = post_type_supports( $post_type, 'convert-to-blocks' );
$use_defaults = apply_filters( 'convert_to_blocks_defaults', true );
$default_post_types = $this->get_default_post_types();
$supports = post_type_supports( $post_type, 'convert-to-blocks' );
$use_defaults = apply_filters( 'convert_to_blocks_defaults', true );
$default_post_types = $this->get_default_post_types();
$user_selected_post_types = get_option( sprintf( '%s_post_types', CONVERT_TO_BLOCKS_SLUG ), $default_post_types );

if ( ! $supports && $use_defaults && in_array( $post_type, $default_post_types, true ) ) {
$supports = true;
}

// For user-selected option via the Settings UI.
if ( false !== $user_selected_post_types ) {
$supports = false;

// If no post_type is selected.
if ( empty( $user_selected_post_types ) ) {
$supports = false;
}

// Check if post_type is selected by the user.
if ( in_array( $post_type, $user_selected_post_types, true ) ) {
$supports = true;
}
}

$supports = apply_filters( 'post_type_supports_convert_to_blocks', $supports, $post_type );

return $supports;
Expand Down Expand Up @@ -255,7 +272,7 @@ public function is_classic_editor_post( $post_id ) {
* @return array
*/
public function get_default_post_types() {
return apply_filters( 'convert_to_blocks_default_post_types', [ 'post', 'page' ] );
return apply_filters( 'convert_to_blocks_default_post_types', CONVERT_TO_BLOCKS_DEFAULT_POST_TYPES );
}

/**
Expand Down
Loading