--- a/wplegalpages/admin/class-wp-legal-pages-admin.php
+++ b/wplegalpages/admin/class-wp-legal-pages-admin.php
@@ -80,6 +80,8 @@
add_filter( 'the_content', array( $this, 'wplegalpages_pro_post_content' ) );
}
add_action('wp_ajax_gdpr_install_plugin', array($this, 'wplp_gdpr_install_plugin_ajax_handler'));
+ add_action( 'save_post', array($this, 'wplp_update_policy_preview'));
+ add_action( 'rest_api_init', array($this, 'allow_cors_for_react_app'));
add_action('rest_api_init', array($this, 'register_wpl_dashboard_route'));
add_action('rest_api_init', array($this, 'wplp_generate_api_secret'));
}
@@ -99,6 +101,69 @@
wp_enqueue_style( $this->plugin_name );
wp_enqueue_style( $this->plugin_name . '-review-notice' );
}
+
+ /* Update Policy preview in the options table */
+ public function wplp_update_policy_preview() {
+ $policy_preview = array();
+
+ global $wpdb;
+ $post_tbl = $wpdb->prefix . 'posts';
+ $postmeta_tbl = $wpdb->prefix . 'postmeta';
+ $pagesresult = $wpdb->get_results(
+ $wpdb->prepare(
+ "
+ SELECT ptbl.*
+ FROM {$post_tbl} AS ptbl
+ INNER JOIN {$postmeta_tbl} AS pmtbl
+ ON ptbl.ID = pmtbl.post_id
+ WHERE ptbl.post_status = %s
+ AND pmtbl.meta_key = %s
+ ORDER BY ptbl.post_date DESC
+ LIMIT 5
+ ",
+ 'publish',
+ 'is_legal'
+ )
+ ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
+
+ foreach ( $pagesresult as $res ) {
+ $policy_preview[] = array(
+ 'name' => $res->post_title,
+ 'last_update' => gmdate( 'Y/m/d H:i:s', strtotime( $res->post_date ) ),
+ 'image_key' => $res->post_name,
+ 'content' => $res->post_content,
+ );
+ }
+
+ if ( get_option( 'policy_preview' ) === false ) {
+ add_option( 'policy_preview', $policy_preview );
+ } else {
+ update_option( 'policy_preview', $policy_preview );
+ }
+ }
+
+ /**
+ * Fucntion to allow cors for react app
+ */
+ public function allow_cors_for_react_app(){
+ remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
+
+ // Add our own permissive CORS headers
+ add_filter( 'rest_pre_serve_request', function( $value ) {
+ header( 'Access-Control-Allow-Origin: https://app.wplegalpages.com' );
+ header( 'Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS' );
+ header( 'Access-Control-Allow-Credentials: true' );
+ header( 'Access-Control-Allow-Headers: Authorization, Content-Type, X-WP-Nonce, Origin, X-Requested-With, Accept' );
+
+ // Handle preflight requests
+ if ( $_SERVER['REQUEST_METHOD'] === 'OPTIONS' ) {
+ status_header( 200 );
+ exit;
+ }
+
+ return $value;
+ });
+ }
/**
@@ -110,9 +175,63 @@
require_once plugin_dir_path( __DIR__ ) . 'includes/settings/class-wp-legal-pages-settings.php';
global $is_user_connected, $api_user_plan; // Make global variables accessible
$this->settings = new WP_Legal_Pages_Settings();
+
+ $master_key = $this->settings->get('api','token');
$is_user_connected = $this->settings->is_connected();
+ register_rest_route(
+ 'wplp-react/v1', //New namespace for React dashboard
+ '/get_dashboard-data',
+ array(
+ 'methods' => 'POST',
+ 'callback' => array($this, 'wplp_send_data_to_dashboard_appwplp_react_app'), // Function to handle the request
+ 'permission_callback' => function(WP_REST_Request $request) use ($master_key) {
+
+
+ $auth_header = isset($_SERVER['HTTP_AUTHORIZATION']) ? $_SERVER['HTTP_AUTHORIZATION'] : '';
+ if ( ! preg_match('/Bearers(S+)/', $auth_header, $matches) ) {
+ return new WP_Error('no_token', 'Authorization token missing.', ['status' => 401]);
+ }
+ $token = sanitize_text_field($matches[1]);
+
+ // 2. Validate token with central WP site
+ $validate = wp_remote_post(
+ 'https://app.wplegalpages.com/wp-json/jwt-auth/v1/token/validate',
+ [
+ 'headers' => [
+ 'Authorization' => 'Bearer ' . $token,
+ 'Content-Type' => 'application/json'
+ ],
+ 'timeout' => 15
+ ]
+ );
+
+ if ( is_wp_error($validate) ) {
+ return new WP_Error('token_validation_failed', $validate->get_error_message(), ['status' => 401]);
+ }
+
+ $code = wp_remote_retrieve_response_code($validate);
+ if ( $code !== 200 ) {
+ return new WP_Error('invalid_token', 'Token validation failed.', ['status' => 401]);
+ }
+
+ // 3. Extract master_key from the request body
+ $body = $request->get_json_params();
+ $incoming_key = isset($body['master_key']) ? sanitize_text_field($body['master_key']) : '';
+
+ if ( empty($incoming_key) ) {
+ return new WP_Error('master_key_missing', 'Master key not provided.', ['status' => 401]);
+ }
+
+ if ( $master_key !== $incoming_key ) {
+ return new WP_Error('invalid_master_key', 'Master key mismatch.', ['status' => 401]);
+ }
+
+ return true; // All good → allow callback
+ },
+ )
+ );
register_rest_route(
'wpl/v2', // Namespace
@@ -355,7 +474,8 @@
);
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
- $titles = array_column($pagesresult, 'post_title');
+ $titles = array_column($pagesresult, 'post_title');
+ $policy_preview = get_option('policy_preview', array());
return rest_ensure_response(
array(
@@ -367,6 +487,52 @@
'page_results' => $titles,
'client_site_name' => $client_site_name,
'api_secret' => get_option('wplegalpages_api_secret'),
+ 'policy_preview' => $policy_preview,
+ )
+ );
+ }
+
+ /* Added endpoint to send dashboard data from plugin to the saas react dashboard */
+ public function wplp_send_data_to_dashboard_appwplp_react_app(WP_REST_Request $request ){
+ ob_start();
+
+ require_once plugin_dir_path( __DIR__ ) . 'includes/settings/class-wp-legal-pages-settings.php';
+
+ $this->settings = new WP_Legal_Pages_Settings();
+ $api_user_plan = $this->settings->get_plan();
+ $product_id = $this->settings->get( 'account', 'product_id' );
+
+ global $wpdb;
+ $post_tbl = $wpdb->prefix . 'posts';
+ $postmeta_tbl = $wpdb->prefix . 'postmeta';
+ $post_tbl = esc_sql( $post_tbl );
+ $postmeta_tbl = esc_sql( $postmeta_tbl );
+
+ // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $count = $wpdb->get_var(
+ $wpdb->prepare(
+ "
+ SELECT COUNT(*)
+ FROM {$post_tbl} AS ptbl, {$postmeta_tbl} AS pmtbl
+ WHERE ptbl.ID = pmtbl.post_id
+ AND ptbl.post_status = %s
+ AND pmtbl.meta_key = %s
+ ",
+ 'publish',
+ 'is_legal'
+ )
+ );
+
+ $policy_preview = get_option('policy_preview', array());
+
+ ob_end_clean();
+ return rest_ensure_response(
+ array(
+ 'success' => true,
+ 'user_plan' => $api_user_plan,
+ 'product_id' => $product_id,
+ 'legal_pages_published' => $count,
+ 'policy_preview' => $policy_preview,
)
);
}
@@ -467,20 +633,20 @@
wp_register_script( $this->plugin_name . '-select2', plugin_dir_url( __FILE__ ) . 'wizard/libraries/select2/select2.js', array( 'jquery' ), $this->version, false );
}
- //public function wplp_remove_dashboard_submenu() {
- // Define the current version constant
- // $current_version = $this->version;
+ // public function wplp_remove_dashboard_submenu() {
+ // // Define the current version constant
+ // $current_version = $this->version;
- // Target version to hide the submenu
- // $target_version = '3.5.4';
+ // // Target version to hide the submenu
+ // $target_version = '3.5.5';
// Check if the current version is below the target version
- // if (version_compare($current_version, $target_version, '<')) {
- // Remove the 'Dashboard' submenu
- // remove_submenu_page('wp-legal-pages', 'wplp-dashboard');
- // remove_submenu_page('wp-legal-pages', 'wplp-dashboard#help-page');
- // }
- //}
+ // if (version_compare($current_version, $target_version, '<')) {
+ // // Remove the 'Dashboard' submenu
+ // remove_submenu_page('wp-legal-pages', 'wplp-dashboard');
+ // remove_submenu_page('wp-legal-pages', 'wplp-dashboard#help-page');
+ // }
+ // }
/**
* This function is provided for WordPress dashbord menus.
*
--- a/wplegalpages/admin/partials/wp-legal-pages-main-screen-dashboard.php
+++ b/wplegalpages/admin/partials/wp-legal-pages-main-screen-dashboard.php
@@ -44,6 +44,7 @@
</div>
<!-- <div id="wplegalpages-save-settings-alert"><img src="<?php echo esc_url( WPL_LITE_PLUGIN_URL . 'admin/js/vue/images/settings_saved.svg' ); ?>" alt="create legal" class="wplegal-save-settings-icon"><?php esc_attr_e( 'Settings saved successfully', 'wplegalpages' ); ?></div> --> <?php //phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage ?>
<div class="wp-legalpages-admin-help-and-support">
+ <div class="wp-legalpages-new-dashboard-btn"><a href="<?php echo esc_url( 'https://app.wplegalpages.com/app/' ); ?>"><?php esc_html_e( 'Try New Dashboard', 'wplegalpages' ); ?></a></div>
<div class="wp-legalpages-admin-help">
<div class="wp-legalpages-admin-help-icon">
<!-- //image -->
--- a/wplegalpages/admin/partials/wp-legal-pages-main-screen.php
+++ b/wplegalpages/admin/partials/wp-legal-pages-main-screen.php
@@ -44,6 +44,7 @@
</div>
<!-- <div id="wplegalpages-save-settings-alert"><img src="<?php echo esc_url( WPL_LITE_PLUGIN_URL . 'admin/js/vue/images/settings_saved.svg' ); ?>" alt="create legal" class="wplegal-save-settings-icon"><?php esc_attr_e( 'Settings saved successfully', 'wplegalpages' ); ?></div> --> <?php //phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage ?>
<div class="wp-legalpages-admin-help-and-support">
+ <div class="wp-legalpages-new-dashboard-btn"><a href="<?php echo esc_url( 'https://app.wplegalpages.com/app/' ); ?>"><?php esc_html_e( 'Try New Dashboard', 'wplegalpages' ); ?></a></div>
<div class="wp-legalpages-admin-help">
<div class="wp-legalpages-admin-help-icon">
<!-- //image -->
--- a/wplegalpages/admin/show-pages.php
+++ b/wplegalpages/admin/show-pages.php
@@ -86,31 +86,33 @@
$postmeta_tbl = $wpdb->prefix . 'postmeta';
$pagesresult = $wpdb->get_results( $wpdb->prepare( 'SELECT ptbl.* FROM ' . $post_tbl . ' as ptbl , ' . $postmeta_tbl . ' as pmtbl WHERE ptbl.ID = pmtbl.post_id and ptbl.post_status = %s AND pmtbl.meta_key = %s', array( 'publish', 'is_legal' ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
- if ( $pagesresult ) {
- $nonce = wp_create_nonce( 'my-nonce' );
- $count = 1;
- $user_tbl = $wpdb->prefix . 'users';
- foreach ( $pagesresult as $res ) {
- $url = get_permalink( $res->ID );
- $author = $wpdb->get_results( $wpdb->prepare( 'SELECT utbl.user_login FROM ' . $post_tbl . ' as ptbl, ' . $user_tbl . ' as utbl WHERE ptbl.post_author = utbl.ID and ptbl.ID = %d', array( $res->ID ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
- $delurl = isset( $_SERVER['PHP_SELF'] ) ? esc_url_raw( wp_unslash( $_SERVER['PHP_SELF'] ) ) : '';
- $delurl .= "?pid=$res->ID&page=$current_page&mode=delete&_wpnonce=$nonce";
+ $policy_preview = array();
+
+ if ( $pagesresult ) {
+ $nonce = wp_create_nonce( 'my-nonce' );
+ $count = 1;
+ $user_tbl = $wpdb->prefix . 'users';
+ foreach ( $pagesresult as $res ) {
+ $url = get_permalink( $res->ID );
+ $author = $wpdb->get_results( $wpdb->prepare( 'SELECT utbl.user_login FROM ' . $post_tbl . ' as ptbl, ' . $user_tbl . ' as utbl WHERE ptbl.post_author = utbl.ID and ptbl.ID = %d', array( $res->ID ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
+ $delurl = isset( $_SERVER['PHP_SELF'] ) ? esc_url_raw( wp_unslash( $_SERVER['PHP_SELF'] ) ) : '';
+ $delurl .= "?pid=$res->ID&page=$current_page&mode=delete&_wpnonce=$nonce";
+ ?>
+ <tr>
+ <td><?php echo esc_attr( $count ); ?></td>
+ <td><?php echo esc_attr( $res->post_title ); ?></td>
+ <td><?php echo esc_attr( $res->ID ); ?></td>
+ <td><?php echo '[wplegalpage pid=' . esc_attr( $res->ID ) . ']'; ?></td>
+ <td><?php echo esc_attr( ucfirst( $author[0]->user_login ) ); ?></td>
+ <td><?php echo esc_attr( gmdate( 'Y/m/d', strtotime( $res->post_date ) ) ); ?></td>
+ <td class="wplegal-table-link">
+ <a href="<?php echo esc_attr( get_admin_url() ); ?>/post.php?post=<?php echo esc_attr( $res->ID ); ?>&action=edit" class="table-link"><?php esc_attr_e( 'Edit ', 'wplegalpages' ); ?></a> | <a href="<?php echo esc_url_raw( $url ); ?>" class="table-link"><?php esc_attr_e( ' View ', 'wplegalpages' ); ?></a>| <a href="<?php echo esc_url_raw( $delurl ); ?>" class="table-link table-link-alert"><?php esc_attr_e( ' Trash', 'wplegalpages' ); ?></a>
+ </td>
+ </tr>
+ <?php
+ $count++;
+ }
?>
- <tr>
- <td><?php echo esc_attr( $count ); ?></td>
- <td><?php echo esc_attr( $res->post_title ); ?></td>
- <td><?php echo esc_attr( $res->ID ); ?></td>
- <td><?php echo '[wplegalpage pid=' . esc_attr( $res->ID ) . ']'; ?></td>
- <td><?php echo esc_attr( ucfirst( $author[0]->user_login ) ); ?></td>
- <td><?php echo esc_attr( gmdate( 'Y/m/d', strtotime( $res->post_date ) ) ); ?></td>
- <td class="wplegal-table-link">
- <a href="<?php echo esc_attr( get_admin_url() ); ?>/post.php?post=<?php echo esc_attr( $res->ID ); ?>&action=edit" class="table-link"><?php esc_attr_e( 'Edit ', 'wplegalpages' ); ?></a> | <a href="<?php echo esc_url_raw( $url ); ?>" class="table-link"><?php esc_attr_e( ' View ', 'wplegalpages' ); ?></a>| <a href="<?php echo esc_url_raw( $delurl ); ?>" class="table-link table-link-alert"><?php esc_attr_e( ' Trash', 'wplegalpages' ); ?></a>
- </td>
- </tr>
- <?php
- $count++;
- }
- ?>
<?php } else { ?>
<tr>
--- a/wplegalpages/includes/class-wp-legal-pages.php
+++ b/wplegalpages/includes/class-wp-legal-pages.php
@@ -124,7 +124,7 @@
global $table_prefix;
$this->plugin_name = 'wp-legal-pages';
- $this->version = '3.5.4';
+ $this->version = '3.5.5';
$this->tablename = $table_prefix . 'legal_pages';
$this->popuptable = $table_prefix . 'lp_popups';
$this->plugin_url = plugin_dir_path( __DIR__ );
@@ -239,7 +239,7 @@
private function define_admin_hooks() {
$plugin_admin = new WP_Legal_Pages_Admin( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_action( 'admin_menu', $plugin_admin, 'admin_menu' );
- //$this->loader->add_action( 'admin_menu', $plugin_admin, 'wplp_remove_dashboard_submenu');
+ // $this->loader->add_action( 'admin_menu', $plugin_admin, 'wplp_remove_dashboard_submenu');
$this->loader->add_action('wp_ajax_wplegalpages_support_request', $plugin_admin, 'wplegalpages_support_request_handler');
$this->loader->add_action('wp_ajax_nopriv_wplegalpages_support_request', $plugin_admin, 'wplegalpages_support_request_handler');
$this->loader->add_action( 'admin_init', $plugin_admin, 'wplegalpages_hidden_meta_boxes' );
--- a/wplegalpages/wplegalpages.php
+++ b/wplegalpages/wplegalpages.php
@@ -4,7 +4,7 @@
* Plugin URI: https://club.wpeka.com/
* Description: WPLegalPages is a simple 1 click legal page management plugin. You can quickly add in legal pages to your WordPress sites.
* Author: WP Legal Pages
- * Version: 3.5.4
+ * Version: 3.5.5
* Author URI: https://wplegalpages.com
* License: GPL2
* Text Domain: wplegalpages