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

Release #818

Merged
merged 12 commits into from
Dec 18, 2023
16 changes: 10 additions & 6 deletions composer.lock

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

50 changes: 50 additions & 0 deletions obfx_modules/header-footer-scripts/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,56 @@ public function hooks() {

$this->loader->add_action( 'wp_head', $this, 'do_header_scripts' );
$this->loader->add_action( 'wp_footer', $this, 'do_footer_scripts' );

/**
* Since we allow for the script meta to be unfiltered, we need to make sure that
* the current user is allowed to add unfiltered html. If not we prevent the meta from being saved or listed.
*/
$this->loader->add_filter( 'add_post_metadata', $this, 'check_post_metadata', 10, 5 );
$this->loader->add_filter( 'update_post_metadata', $this, 'check_post_metadata', 10, 5 );
$this->loader->add_filter( 'is_protected_meta', $this, 'is_meta_protected', 10, 3 );
}

/**
* Check if meta is protected.
*
* @param bool $protected Whether the key is considered protected.
* @param string $meta_key Metadata key.
* @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', or any other object type with an associated meta table.
*
* @return bool
*/
final public function is_meta_protected( $protected, $meta_key, $meta_type ) {
if ( ! in_array( $meta_key, array( 'obfx-header-scripts', 'obfx-footer-scripts' ), true ) ) {
return $protected;
}

if ( current_user_can( 'unfiltered_html' ) ) {
return $protected;
}

return true;
}

/**
* @param null | bool $check Whether the meta key is allowed for update or add actions.
* @param int $object_id Object ID.
* @param string $meta_key Metadata key.
* @param mixed $meta_value Metadata value.
* @param mixed $prev_value Previous value of metadata.
*
* @return null | bool
*/
final public function check_post_metadata( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
if ( ! in_array( $meta_key, array( 'obfx-header-scripts', 'obfx-footer-scripts' ), true ) ) {
return $check;
}

if ( current_user_can( 'unfiltered_html' ) ) {
return $check;
}

return false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion obfx_modules/template-directory/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function admin_enqueue() {
'cta' => $this->get_state( 'tpc' ),
'activate' => $this->get_tcp_activation_link(),
),
'tpcAdminURL' => ( defined( 'NEVE_COMPATIBILITY_FEATURES' ) && isset( NEVE_COMPATIBILITY_FEATURES['theme_dedicated_menu'] ) ) ? admin_url( 'admin.php?page=tiob-starter-sites' ) : admin_url( 'themes.php?page=tiob-starter-sites' ),
'tpcAdminURL' => admin_url( 'admin.php?page=tiob-starter-sites' ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'strings' => array(
'themeNotInstalled' => __( 'In order to import any starter sites, Neve theme & Templates Cloud plugin need to be installed and activated. Click the button below to install and activate Neve.', 'themeisle-companion' ),
Expand Down
Loading