Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f761742
Just in case commit
cbravobernal Apr 11, 2025
65768f5
Use only one file
cbravobernal Apr 21, 2025
1050e0c
Fix header
cbravobernal Apr 21, 2025
62de2ac
Add sidebar experiment
cbravobernal Apr 22, 2025
46eafd1
Add prettier, typescript and hide the experiment for production site
cbravobernal Apr 23, 2025
df5362e
Update wp scripts
cbravobernal Apr 23, 2025
b940016
Add some small fixes
cbravobernal Apr 23, 2025
a139f6f
Revert "Update wp scripts"
cbravobernal Apr 23, 2025
e55102f
Use acf object, fix some version numbers
cbravobernal Apr 24, 2025
8cdd4dc
Simplify js files
cbravobernal Apr 24, 2025
8636385
Small refactor, remove readmes
cbravobernal Apr 24, 2025
910a8b4
Remove redundant comments
cbravobernal Apr 24, 2025
d11fd6b
Add no experiments view
cbravobernal Apr 25, 2025
1bba9e9
Move enqueue and localize to the same function
cbravobernal Apr 25, 2025
86f2a47
Address some changes
cbravobernal Apr 25, 2025
899cac7
Remove dates
cbravobernal Apr 25, 2025
0cfa960
Mega movement to use acf localize and rename to beta features
cbravobernal Apr 25, 2025
c3930ad
Some refactor
cbravobernal Apr 25, 2025
4881188
fix
cbravobernal Apr 25, 2025
cf4db82
Remove not needed TS (yet)
cbravobernal Apr 25, 2025
8b71adb
Leave it disabled
cbravobernal Apr 25, 2025
1e32490
Remove unnedded stuff
cbravobernal Apr 29, 2025
da68974
Remove disable filters
cbravobernal Apr 29, 2025
d17afcd
Update version, protect everything possible
cbravobernal Apr 29, 2025
a3b2021
Update version
cbravobernal Apr 29, 2025
5a66327
Disable the experiment, update all
cbravobernal Apr 29, 2025
585ff7b
Check submit must be public
cbravobernal Apr 29, 2025
caa8a1d
Remove not needed function
cbravobernal Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jspm_packages/
*.njsproj
*.sln
.cursorrules
.cursorignore

# Assets build directory
assets/build/**/*.css
Expand Down
287 changes: 287 additions & 0 deletions includes/admin/beta-features.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
<?php // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed
/**
* Admin Beta Features
*
* This file contains the admin beta features functionality for Secure Custom Fields.
*
* @package Secure Custom Fields
* @since 6.5.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

if ( ! class_exists( 'SCF_Admin_Beta_Features' ) ) :
/**
* Class SCF_Admin_Beta_Features
*
* This class provides different beta features that eventually will land on secure custom fields.
*/
class SCF_Admin_Beta_Features {

/**
* Contains an array of admin beta feature instances.
*
* @var array
*/
private $beta_features = array();

/**
* This function will setup the class functionality
*
* @since SCF 6.5.0
*
* @return void
*/
public function __construct() {
// Temporarily disabled - will be enabled when beta feature is ready
// add_action( 'admin_menu', array( $this, 'admin_menu' ), 20 );
}

/**
* This function will store an beta feature class instance in the beta features array.
*
* @since SCF 6.5.0
*
* @param string $beta_feature Class name.
* @return void
*/
public function register_beta_feature( $beta_feature ) {
$instance = new $beta_feature();
$this->beta_features[ $instance->name ] = $instance;
}

/**
* This function will return an beta feature class or null if not found.
*
* @since SCF 6.5.0
*
* @param string $name Name of beta feature.
* @return mixed (SCF_Admin_Beta_Feature|null)
*/
public function get_beta_feature( $name ) {
return isset( $this->beta_features[ $name ] ) ? $this->beta_features[ $name ] : null;
}

/**
* This function will return an array of all beta feature instances.
*
* @since SCF 6.5.0
*
* @return array
*/
public function get_beta_features() {
// Include beta features
$this->include_beta_features();

return $this->beta_features;
}

/**
* Localizes the beta features data.
*
* @since SCF 6.5.0
*
* @return void
*/
public function localize_beta_features() {
$beta_features = array();
foreach ( $this->get_beta_features() as $name => $beta_feature ) {
$beta_features[ $name ] = $beta_feature->is_enabled();
}

acf_localize_data(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do a follow-up and create a REST endpoint for this.

array(
'betaFeatures' => $beta_features,
)
);
}

/**
* This function will add the SCF beta features menu item to the WP admin
*
* @type action (admin_menu)
* @since SCF 6.5.0
*
* @return void
*/
public function admin_menu() {
// bail early if no show_admin
if ( ! acf_get_setting( 'show_admin' ) ) {
return;
}

$page = add_submenu_page( 'edit.php?post_type=acf-field-group', __( 'Beta Features', 'secure-custom-fields' ), __( 'Beta Features', 'secure-custom-fields' ), acf_get_setting( 'capability' ), 'scf-beta-features', array( $this, 'html' ) );

add_action( 'load-' . $page, array( $this, 'load' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'localize_beta_features' ), 20 );
}

/**
* Loads the admin beta features page.
*
* @since SCF 6.5.0
*
* @return void
*/
public function load() {
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
// Include and register beta features before checking submit
$this->include_beta_features();

$this->check_submit();
}

/**
* Modifies the admin body class.
*
* @since SCF 6.5.0
*
* @param string $classes Space-separated list of CSS classes.
* @return string
*/
public function admin_body_class( $classes ) {
$classes .= ' acf-admin-page';
return $classes;
}

/**
* Includes various beta feature-related files.
*
* @since SCF 6.5.0
*
* @return void
*/
private function include_beta_features() {
acf_include( 'includes/admin/beta-features/class-scf-beta-feature.php' );
acf_include( 'includes/admin/beta-features/class-scf-beta-feature-editor-sidebar.php' );

add_action( 'scf/include_admin_beta_features', array( $this, 'register_beta_features' ) );

do_action( 'scf/include_admin_beta_features' );
}

/**
* Register default beta features.
*
* @since SCF 6.5.0
*
* @return void
*/
public function register_beta_features() {
scf_register_admin_beta_feature( 'SCF_Admin_Beta_Feature_Editor_Sidebar' );
}

/**
* Verifies the nonces and submits the value if it passes.
*
* @since SCF 6.5.0
*
* @return void
*/
public function check_submit() {
// Check if form was submitted.
if ( ! isset( $_POST['scf_beta_features_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['scf_beta_features_nonce'] ), 'scf_beta_features_update' ) ) {
return;
}

$beta_features = $this->get_beta_features();
$updated = false;

foreach ( $beta_features as $name => $beta_feature ) {
$enabled = isset( $_POST['scf_beta_features'][ $name ] ) && '1' === $_POST['scf_beta_features'][ $name ];
$beta_feature->set_enabled( $enabled );
$updated = true;
}

if ( $updated ) {
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
}
}

/**
* Display admin notices.
*
* @since SCF 6.5.0
*
* @return void
*/
public function admin_notices() {
?>
<div class="notice notice-success is-dismissible">
<p><?php esc_html_e( 'Beta feature settings updated successfully.', 'secure-custom-fields' ); ?></p>
</div>
<?php
}

/**
* Admin Beta Features html
*
* @since SCF 6.5.0
*
* @return void
*/
public function html() {
// vars
$screen = get_current_screen();

// view
$view = array(
'screen_id' => $screen->id,
);

foreach ( $this->get_beta_features() as $name => $beta_feature ) {
add_meta_box( 'scf-admin-beta-feature-' . $name, acf_esc_html( $beta_feature->title ), array( $this, 'metabox_html' ), $screen->id, 'normal', 'default', array( 'beta_feature' => $name ) );
}

acf_get_view( 'beta-features/beta-features', $view );
}

/**
* Output the metabox HTML for specific beta features
*
* @since SCF 6.5.0
*
* @param mixed $post The post this metabox is being displayed on, should be an empty string always for us on an beta features page.
* @param array $metabox An array of the metabox attributes.
*/
public function metabox_html( $post, $metabox ) {
$beta_feature = $this->get_beta_feature( $metabox['args']['beta_feature'] );
$form_attrs = array( 'method' => 'post' );

printf( '<form %s>', acf_esc_attrs( $form_attrs ) );
$beta_feature->html();
acf_nonce_input( $beta_feature->name );
echo '</form>';
}
}

// initialize
acf()->admin_beta_features = new SCF_Admin_Beta_Features();
endif; // class_exists check

/**
* Alias of acf()->admin_beta_features->register_beta_feature()
*
* @type function
* @since SCF 6.5.0
*
* @param string $beta_feature The beta feature class.
* @return void
*/
function scf_register_admin_beta_feature( $beta_feature ) {
acf()->admin_beta_features->register_beta_feature( $beta_feature );
}

/**
* This function will return the admin URL to the beta features page
*
* @type function
* @since SCF 6.5.0
*
* @return string The URL to the beta features page.
*/
function scf_get_admin_beta_features_url() {
return admin_url( 'edit.php?post_type=acf-field-group&page=scf-beta-features' );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Editor Sidebar Beta Feature
*
* This beta feature allows moving field group elements to the editor sidebar.
*
* @package Secure Custom Fields
* @since 6.5.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

if ( ! class_exists( 'SCF_Admin_Beta_Feature_Editor_Sidebar' ) ) :
/**
* Class SCF_Admin_Beta_Feature_Editor_Sidebar
*
* Implements a beta feature to move field group elements to the editor sidebar
* for a cleaner interface.
*
* @package Secure Custom Fields
* @since 6.5.0
*/
class SCF_Admin_Beta_Feature_Editor_Sidebar extends SCF_Admin_Beta_Feature {

/**
* Initialize the beta feature.
*
* @return void
*/
protected function initialize() {
$this->name = 'editor-sidebar';
$this->title = __( 'Move Elements to Editor Sidebar', 'secure-custom-fields' );
$this->description = __( 'Moves field group elements to the editor sidebar for a cleaner interface.', 'secure-custom-fields' );

if ( $this->is_enabled() ) {
add_action( 'admin_init', array( $this, 'setup_beta_feature' ) );
}
}
}
endif;
Loading
Loading