Initial commit xmarticaims
This commit is contained in:
+309
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin page for handling 1-click install of public snippets in the WPCode library.
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for the 1-Click admin page.
|
||||
*/
|
||||
class WPCode_Admin_Page_Click extends WPCode_Admin_Page {
|
||||
|
||||
/**
|
||||
* The page slug to be used when adding the submenu.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $page_slug = 'wpcode-click';
|
||||
|
||||
/**
|
||||
* The action used for the nonce.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $action = 'wpcode-click';
|
||||
|
||||
/**
|
||||
* The nonce name field.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $nonce_name = 'wpcode-click_nonce';
|
||||
|
||||
/**
|
||||
* Hide this page in the menu.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hide_menu = true;
|
||||
|
||||
/**
|
||||
* Call this just to set the page title translatable.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->page_title = __( '1-Click', 'insert-headers-and-footers' );
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hook on admin init just for this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_hooks() {
|
||||
add_action( 'admin_init', array( $this, 'submit_listener' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to hide default header on this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap this page in a form tag.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output() {
|
||||
?>
|
||||
<form action="<?php echo esc_url( $this->get_page_action_url() ); ?>" method="post">
|
||||
<?php parent::output(); ?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* The page output.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_content() {
|
||||
?>
|
||||
<div class="wpcode-modal-area">
|
||||
<div class="wpcode-modal-header">
|
||||
<?php $this->logo_image(); ?>
|
||||
</div>
|
||||
<?php
|
||||
$snippet_hash = get_transient( 'wpcode_deploy_snippet_id' );
|
||||
// Let's see if we're in the middle of a fresh installation from the library.
|
||||
if ( isset( $_GET['message'] ) && 'wpcode-deploy' === $_GET['message'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( ! wpcode()->library_auth->has_auth() ) {
|
||||
?>
|
||||
<h3><?php esc_html_e( 'Connect your site to the WPCode Library', 'insert-headers-and-footers' ); ?></h3>
|
||||
<p><?php esc_html_e( 'You\'re almost there! To finish installing the snippet, you need to connect your site to your account on the WPCode Library. This will allow you to install snippets directly to your site in the future.', 'insert-headers-and-footers' ); ?></p>
|
||||
<p><?php esc_html_e( 'You\'ll also get access to tens of free expert-curated snippets that can be installed with 1-click from inside the plugin.', 'insert-headers-and-footers' ); ?></p>
|
||||
<div class="wpcode-buttons-row">
|
||||
<button class="wpcode-button wpcode-button-large wpcode-start-auth">
|
||||
<?php esc_html_e( 'Connect to Library', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
// The site is connected to the library but it must mean it's connected to another account in which case they should connect to their own account.
|
||||
?>
|
||||
<h3><?php esc_html_e( 'Your site is already connected to the WPCode Library using another account', 'insert-headers-and-footers' ); ?></h3>
|
||||
<p>
|
||||
<?php esc_html_e( 'In order to continue installing the snippet from the WPCode library you have to either login to the Library with the same account used to connect this site to the WPCode library initially or disconnect this site from the WPCode library and connect using your own account.', 'insert-headers-and-footers' ); ?>
|
||||
</p>
|
||||
<div class="wpcode-buttons-row">
|
||||
<button class="wpcode-button wpcode-delete-auth">
|
||||
<?php esc_html_e( 'Disconnect Site From Library', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<a class="wpcode-button" href="<?php echo esc_url( wpcode()->library_auth->library_url ); ?>/account">
|
||||
<?php esc_html_e( 'Login with another user on the WPCode Library', 'insert-headers-and-footers' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
} elseif ( false !== $snippet_hash && wpcode()->library_auth->has_auth() && ! isset( $_GET['snippet'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
// We have a snippet hash so let's continue the snippet install process.
|
||||
$snippet_url = wpcode()->library_auth->library_url . '/snippet/' . $snippet_hash . '/?deploy=1';
|
||||
?>
|
||||
<h3><?php esc_html_e( 'Congratulations, your site is now connected!', 'insert-headers-and-footers' ); ?></h3>
|
||||
<p><?php esc_html_e( 'Your site is now connected to the WPCode Library and you can install snippets directly from the library. Please click the button below to resume installing the snippet you were viewing.', 'insert-headers-and-footers' ); ?></p>
|
||||
<div class="wpcode-buttons-row">
|
||||
<a href="<?php echo esc_url( $snippet_url ); ?>" class="wpcode-button wpcode-button-large">
|
||||
<?php esc_html_e( 'Resume Snippet Installation', 'insert-headers-and-footers' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php
|
||||
delete_transient( 'wpcode_deploy_snippet_id' );
|
||||
} elseif ( ! wpcode()->library_auth->has_auth() ) { // Let's make sure the site is authenticated with the library.
|
||||
?>
|
||||
<h3><?php esc_html_e( 'Your site is not connected to the WPCode library.', 'insert-headers-and-footers' ); ?></h3>
|
||||
<p><?php esc_html_e( 'Connect now to enable installing public snippets from the WPCode library with 1-click and also get access to tens of expert-curated snippets that you can install from inside the plugin.', 'insert-headers-and-footers' ); ?></p>
|
||||
<div class="wpcode-buttons-row">
|
||||
<button class="wpcode-button wpcode-button-large wpcode-start-auth">
|
||||
<?php esc_html_e( 'Connect to Library', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
// Let's check that we have a snippet hash to load.
|
||||
} elseif ( empty( $_GET['snippet'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<p><?php esc_html_e( 'No snippet provided.', 'insert-headers-and-footers' ); ?></p>
|
||||
</div>
|
||||
<?php
|
||||
// Let's check that the site is authenticated.
|
||||
} elseif ( empty( $_GET['auth'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<p><?php esc_html_e( 'Missing authentication token, please click the link in the WPCode Library again.', 'insert-headers-and-footers' ); ?></p>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
// Let's make sure they don't get redirect again if they reached this point.
|
||||
delete_transient( 'wpcode_deploy_snippet_id' );
|
||||
// Let's attempt to load the snippet data from the library.
|
||||
$auth = sanitize_key( $_GET['auth'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$snippet_hash = sanitize_key( $_GET['snippet'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$snippet_request = wpcode()->library->get_public_snippet( $snippet_hash, $auth );
|
||||
|
||||
if ( ! isset( $snippet_request['status'] ) || 'success' !== $snippet_request['status'] ) {
|
||||
// We have an error. Let's default to a generic message.
|
||||
$error = __( 'We encountered an error loading your snippet, please try again in a few minutes', 'insert-headers-and-footers' );
|
||||
if ( isset( $snippet_request['message'] ) ) {
|
||||
// If there is a message, let's use that instead.
|
||||
$error = sprintf(
|
||||
/* translators: %s: The error message from the API. */
|
||||
__( 'We encountered the following error loading your snippet: %s', 'insert-headers-and-footers' ),
|
||||
$snippet_request['message']
|
||||
);
|
||||
}
|
||||
$go_back_url = wpcode()->library_auth->library_url . '/snippet/' . $snippet_hash;
|
||||
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<p><?php echo esc_html( $error ); ?></p>
|
||||
</div>
|
||||
<div class="wpcode-buttons-row">
|
||||
<a href="<?php echo esc_url( $go_back_url ); ?>" class="wpcode-button"><?php esc_html_e( 'Go back to the library', 'insert-headers-and-footers' ); ?></a>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
$snippet = $snippet_request['data'];
|
||||
$snippet_types = wpcode()->execute->get_options();
|
||||
// Let's show a preview of the snippet and ask the user to confirm.
|
||||
?>
|
||||
<h1><?php esc_html_e( 'Library Snippet Preview', 'insert-headers-and-footers' ); ?></h1>
|
||||
<p><?php esc_html_e( 'Please review the snippet below and confirm that you would like to install it.', 'insert-headers-and-footers' ); ?></p>
|
||||
<h3>
|
||||
<?php
|
||||
// Translators: %s: The snippet name.
|
||||
printf( esc_html__( 'Snippet title: %s', 'insert-headers-and-footers' ), esc_html( $snippet['title'] ) );
|
||||
?>
|
||||
</h3>
|
||||
<div class="wpcode-code-textarea">
|
||||
<div class="wpcode-flex">
|
||||
<div class="wpcode-column">
|
||||
<h3><?php esc_html_e( 'Code preview', 'insert-headers-and-footers' ); ?></h3>
|
||||
</div>
|
||||
<div class="wpcode-column">
|
||||
<div class="wpcode-input-select">
|
||||
<label for="wpcode_snippet_type"><?php esc_html_e( 'Code Type', 'insert-headers-and-footers' ); ?></label>
|
||||
<select disabled>
|
||||
<?php
|
||||
foreach ( $snippet_types as $key => $label ) {
|
||||
if ( $key !== $snippet['code_type'] ) {
|
||||
continue;
|
||||
}
|
||||
?>
|
||||
<option selected><?php echo esc_html( $label ); ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<textarea id="wpcode-code-preview"><?php echo esc_textarea( $snippet['code'] ); ?></textarea>
|
||||
</div>
|
||||
<div class="wpcode-buttons-row">
|
||||
<input type="hidden" name="snippet" value="<?php echo esc_attr( $snippet['cloud_id'] ); ?>">
|
||||
<input type="hidden" name="auth" value="<?php echo esc_attr( $auth ); ?>">
|
||||
<button class="wpcode-button wpcode-button-large"><?php esc_html_e( 'Confirm & Install Snippet', 'insert-headers-and-footers' ); ?></button>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
$editor = new WPCode_Code_Editor( esc_js( $snippet['code_type'] ) );
|
||||
$editor->set_setting( 'readOnly', 'nocursor' );
|
||||
$editor->register_editor( 'wpcode-code-preview' );
|
||||
$editor->init_editor();
|
||||
}
|
||||
|
||||
wp_nonce_field( $this->action, $this->nonce_name );
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* For this page we output a title and the save button.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header_bottom() {
|
||||
?>
|
||||
<div class="wpcode-column">
|
||||
<h1><?php esc_html_e( 'Confirm Snippet Installation', 'insert-headers-and-footers' ); ?></h1>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* If the form is submitted attempt to save the values.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function submit_listener() {
|
||||
if ( ! isset( $_REQUEST[ $this->nonce_name ] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST[ $this->nonce_name ] ), $this->action ) ) {
|
||||
// Nonce is missing, so we're not even going to try.
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'wpcode_edit_snippets' ) ) {
|
||||
// Should not be able to load this page at all without that permission but let's check anyway.
|
||||
return;
|
||||
}
|
||||
|
||||
$snippet_hash = isset( $_REQUEST['snippet'] ) ? sanitize_key( $_REQUEST['snippet'] ) : false;
|
||||
$auth = isset( $_REQUEST['auth'] ) ? sanitize_key( $_REQUEST['auth'] ) : false;
|
||||
// Let's load the data reliably again - it's saved in a transient so it should be fast.
|
||||
$snippet_data = wpcode()->library->get_public_snippet( $snippet_hash, $auth );
|
||||
|
||||
// You should not be able to submit this form if the hash is invalid but let's check anyway.
|
||||
if ( ! isset( $snippet_data['status'] ) || 'success' !== $snippet_data['status'] ) {
|
||||
// This should not happen if you did not manually change the hash, so we can just return.
|
||||
return;
|
||||
}
|
||||
|
||||
// Drop cloud_id so we don't write My Library meta for a public-library install.
|
||||
if ( isset( $snippet_data['data'] ) && is_array( $snippet_data['data'] ) ) {
|
||||
unset( $snippet_data['data']['cloud_id'] );
|
||||
}
|
||||
|
||||
// Let's create a new snippet.
|
||||
$snippet = new WPCode_Snippet( $snippet_data['data'] );
|
||||
// Let's save the snippet.
|
||||
if ( $snippet->save() ) {
|
||||
// If successfully saved let's redirect to the edit screen.
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
array(
|
||||
'page' => 'wpcode-snippet-manager',
|
||||
'snippet_id' => $snippet->get_id(),
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
+579
@@ -0,0 +1,579 @@
|
||||
<?php
|
||||
/**
|
||||
* Code snippets admin main list page.
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for the code snippets page.
|
||||
*/
|
||||
class WPCode_Admin_Page_Code_Snippets extends WPCode_Admin_Page {
|
||||
|
||||
/**
|
||||
* The page slug to be used when adding the submenu.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $page_slug = 'wpcode';
|
||||
|
||||
/**
|
||||
* Instance of the code snippets table.
|
||||
*
|
||||
* @see WP_List_Table
|
||||
* @var WPCode_Code_Snippets_Table
|
||||
*/
|
||||
protected $snippets_table;
|
||||
|
||||
/**
|
||||
* Call this just to set the page title translatable.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->page_title = __( 'Code Snippets', 'insert-headers-and-footers' );
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Page-specific hooks, init the custom WP_List_Table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_hooks() {
|
||||
$this->process_message();
|
||||
|
||||
add_action( 'current_screen', array( $this, 'init_table' ) );
|
||||
add_action( 'admin_init', array( $this, 'maybe_capture_filter' ) );
|
||||
add_action( 'load-toplevel_page_wpcode', array( $this, 'maybe_process_bulk_action' ) );
|
||||
add_action( 'wpcode_admin_notices', array( $this, 'maybe_show_deactivated_notice' ) );
|
||||
|
||||
// Register Screen options.
|
||||
add_action( 'load-toplevel_page_wpcode', array( $this, 'add_per_page_option' ) );
|
||||
// Hide some columns by default.
|
||||
add_filter( 'default_hidden_columns', array( $this, 'hide_columns' ), 10, 2 );
|
||||
add_filter( 'wpcode_admin_js_data', array( $this, 'prepare_admin_js_localization_data' ) );
|
||||
add_filter( 'screen_settings', array( $this, 'add_custom_screen_option' ), 10, 2 );
|
||||
// Hide the duplicated parameter from the URL.
|
||||
add_filter( 'removable_query_args', array( $this, 'remove_query_arg_from_url' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* If the referer is set, remove and redirect.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_capture_filter() {
|
||||
if ( ! empty( $_REQUEST['_wp_http_referer'] ) && isset( $_SERVER['REQUEST_URI'] ) && isset( $_REQUEST['filter_action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
wp_safe_redirect(
|
||||
remove_query_arg(
|
||||
array(
|
||||
'_wp_http_referer',
|
||||
'_wpnonce',
|
||||
),
|
||||
wp_unslash( $_SERVER['REQUEST_URI'] ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
if ( ! empty( $_REQUEST['_wp_http_referer'] ) && isset( $_SERVER['REQUEST_URI'] ) && isset( $_REQUEST['filter_clear'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
'page',
|
||||
'wpcode',
|
||||
$this->admin_url( 'admin.php' )
|
||||
)
|
||||
);
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener for bulk actions.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_process_bulk_action() {
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
$ids = isset( $_GET['snippet_id'] ) ? array_map( 'absint', (array) $_GET['snippet_id'] ) : array();
|
||||
$action = isset( $_REQUEST['action'] ) ? sanitize_key( $_REQUEST['action'] ) : false;
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
if ( empty( $ids ) || empty( $action ) ) {
|
||||
return;
|
||||
}
|
||||
if ( empty( $_GET['_wpnonce'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'bulk-wpcode-snippets' ) &&
|
||||
! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'wpcode_' . $action . '_nonce' )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only operate on wpcode snippets the current user is allowed to edit.
|
||||
$ids = array_filter(
|
||||
$ids,
|
||||
function ( $id ) {
|
||||
return 'wpcode' === get_post_type( $id ) && current_user_can( 'edit_post', $id );
|
||||
}
|
||||
);
|
||||
if ( empty( $ids ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$update_status_actions = array( 'trash', 'untrash' );
|
||||
|
||||
if ( in_array( $action, $update_status_actions, true ) ) {
|
||||
$newstatus = 'trash' === $action ? 'trash' : 'draft';
|
||||
foreach ( $ids as $id ) {
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $id,
|
||||
'post_status' => $newstatus,
|
||||
)
|
||||
);
|
||||
}
|
||||
// Clear errors when a snippet is trashed.
|
||||
wpcode()->error->clear_snippets_errors();
|
||||
}
|
||||
if ( 'delete' === $action ) {
|
||||
foreach ( $ids as $id ) {
|
||||
wp_delete_post( $id );
|
||||
}
|
||||
// Clear errors when a snippet is deleted.
|
||||
wpcode()->error->clear_snippets_errors();
|
||||
}
|
||||
$failed = 0;
|
||||
if ( 'enable' === $action ) {
|
||||
foreach ( $ids as $key => $id ) {
|
||||
$snippet = wpcode_get_snippet( $id );
|
||||
$snippet->activate();
|
||||
if ( ! $snippet->active ) {
|
||||
// If failed to activate don't count it.
|
||||
unset( $ids[ $key ] );
|
||||
++ $failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( 'disable' === $action ) {
|
||||
foreach ( $ids as $id ) {
|
||||
$snippet = wpcode_get_snippet( $id );
|
||||
$snippet->deactivate();
|
||||
}
|
||||
}
|
||||
$message = array(
|
||||
rtrim( $action, 'e' ) . 'ed' => count( $ids ),
|
||||
);
|
||||
if ( $failed ) {
|
||||
$message['error'] = $failed;
|
||||
}
|
||||
|
||||
if ( 'duplicate' === $action ) {
|
||||
foreach ( $ids as $id ) {
|
||||
// Load all the snippet data in the object.
|
||||
$snippet = wpcode_get_snippet( $id );
|
||||
$snippet->duplicate();
|
||||
}
|
||||
}
|
||||
|
||||
wpcode()->cache->cache_all_loaded_snippets();
|
||||
|
||||
// Clear used library snippets.
|
||||
delete_transient( 'wpcode_used_library_snippets' );
|
||||
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
$message,
|
||||
remove_query_arg(
|
||||
array(
|
||||
'action',
|
||||
'action2',
|
||||
'_wpnonce',
|
||||
'snippet_id',
|
||||
'paged',
|
||||
'_wp_http_referer',
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the custom table for the snippets list.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init_table() {
|
||||
require_once WPCODE_PLUGIN_PATH . 'includes/admin/pages/class-wpcode-code-snippets-table.php';
|
||||
|
||||
$this->snippets_table = new WPCode_Code_Snippets_Table();
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the custom table and page content.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_content() {
|
||||
$this->snippets_table->prepare_items();
|
||||
|
||||
?>
|
||||
<form id="wpcode-code-snippets-table" method="get" action="<?php echo esc_url( $this->admin_url( 'admin.php?page=wpcode' ) ); ?>">
|
||||
<input type="hidden" name="page" value="wpcode"/>
|
||||
<?php
|
||||
$this->snippets_table->search_box( esc_html__( 'Search Snippets', 'insert-headers-and-footers' ), 'wpcode_snippet_search' );
|
||||
$this->snippets_table->views();
|
||||
$this->snippets_table->display();
|
||||
?>
|
||||
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Footer for this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_footer() {
|
||||
parent::output_footer();
|
||||
?>
|
||||
<div id="wpcode-loader">
|
||||
<div class="wpcode-loader-overlay">
|
||||
<img src="<?php echo esc_url( WPCODE_PLUGIN_URL ) . 'admin/images/spinner.svg'; // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage?>" alt="">
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the snippet types for the filters in a normalized format.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_snippet_types_for_filters() {
|
||||
$types = wpcode()->execute->get_types();
|
||||
$snippet_type = isset( $_GET['type'] ) ? sanitize_text_field( wp_unslash( $_GET['type'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
$type_buttons = array(
|
||||
array(
|
||||
'is_pro' => false,
|
||||
'label' => esc_html__( 'All Snippets', 'insert-headers-and-footers' ),
|
||||
'class' => ! $snippet_type ? 'active' : '',
|
||||
'type' => '',
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $types as $type_key => $type ) {
|
||||
$type_buttons[] = array(
|
||||
'is_pro' => isset( $type['is_pro'] ) ? $type['is_pro'] : false,
|
||||
'label' => $type['filter_label'],
|
||||
'class' => $snippet_type === $type_key ? 'active' : '',
|
||||
'type' => $type_key,
|
||||
);
|
||||
}
|
||||
|
||||
return $this->prepare_type_buttons( $type_buttons );
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorder the buttons and add version-specific info.
|
||||
*
|
||||
* @param array $type_buttons The type buttons.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepare_type_buttons( $type_buttons ) {
|
||||
|
||||
// Reorder items so pro items are always last.
|
||||
usort(
|
||||
$type_buttons,
|
||||
function ( $a, $b ) {
|
||||
if ( $a['is_pro'] === $b['is_pro'] ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $a['is_pro'] ? 1 : - 1;
|
||||
}
|
||||
);
|
||||
|
||||
// Let's go through the items and add the pro class and update the label.
|
||||
foreach ( $type_buttons as $key => $type ) {
|
||||
if ( ! $type['is_pro'] ) {
|
||||
continue;
|
||||
}
|
||||
$type_buttons[ $key ]['label'] = sprintf( '%s (PRO)', $type['label'] );
|
||||
$type_buttons[ $key ]['class'] .= ' wpcode_pro_type_lite';
|
||||
}
|
||||
|
||||
return $type_buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate buttons for available snippet types.
|
||||
*
|
||||
* @return string HTML for the buttons.
|
||||
*/
|
||||
public function get_snippet_type_buttons() {
|
||||
$buttons = $this->get_snippet_types_for_filters();
|
||||
$buttons_html = '';
|
||||
|
||||
foreach ( $buttons as $button ) {
|
||||
$buttons_html .= sprintf(
|
||||
'<li><a class="%1$s" href="#" data-type="%2$s">%3$s</a></li>',
|
||||
esc_attr( $button['class'] ),
|
||||
esc_attr( $button['type'] ),
|
||||
esc_attr( $button['label'] )
|
||||
);
|
||||
}
|
||||
|
||||
return $buttons_html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Content of the bottom row of the header.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header_bottom() {
|
||||
$add_new_url = $this->admin_url( 'admin.php?page=wpcode-snippet-manager' );
|
||||
?>
|
||||
<div class="wpcode-column wpcode-title-button">
|
||||
<ul id="wpcode-snippet-type-buttons" class="wpcode-admin-tabs">
|
||||
<?php echo $this->get_snippet_type_buttons(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</ul>
|
||||
<button class="wpcode-mobile-dropdown-toggle wpcode-button wpcode-button-just-icon" data-target="#wpcode-snippet-type-buttons">
|
||||
<?php wpcode_icon( 'menu', '24', '24', '0 -960 960 960' ); ?>
|
||||
</button>
|
||||
<a class="wpcode-button" href="<?php echo esc_url( $add_new_url ); ?>">
|
||||
<?php esc_html_e( 'Add New', 'insert-headers-and-footers' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture screen-specific messages and add notices.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process_message() {
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification
|
||||
if ( ! empty( $_GET['trashed'] ) ) {
|
||||
$count = absint( $_GET['trashed'] );
|
||||
$notice = sprintf( /* Translators: %d - Trashed snippets count. */
|
||||
_n( '%d snippet was successfully moved to Trash.', '%d snippets were successfully moved to Trash.', $count, 'insert-headers-and-footers' ),
|
||||
$count
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $_GET['untrashed'] ) ) {
|
||||
$count = absint( $_GET['untrashed'] );
|
||||
$notice = sprintf( /* translators: %d - Restored from trash snippets count. */
|
||||
_n( '%d snippet was successfully restored.', '%d snippet were successfully restored.', $count, 'insert-headers-and-footers' ),
|
||||
$count
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $_GET['deleted'] ) ) {
|
||||
$count = absint( $_GET['deleted'] );
|
||||
$notice = sprintf( /* translators: %d - Deleted snippets count. */
|
||||
_n( '%d snippet was successfully permanently deleted.', '%d snippets were successfully permanently deleted.', $count, 'insert-headers-and-footers' ),
|
||||
$count
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset( $_GET['enabled'] ) ) {
|
||||
$count = absint( $_GET['enabled'] );
|
||||
$notice = '';
|
||||
if ( $count > 0 ) {
|
||||
$notice = sprintf( /* translators: %d - Activated snippets count. */
|
||||
_n( '%d snippet was successfully activated.', '%d snippets were successfully activated.', $count, 'insert-headers-and-footers' ),
|
||||
$count
|
||||
);
|
||||
}
|
||||
if ( isset( $_GET['error'] ) ) {
|
||||
$error_count = absint( $_GET['error'] );
|
||||
|
||||
$notice .= ' ';
|
||||
$notice .= sprintf( /* translators: %d - Failed to activate snippets count. */
|
||||
_n( '%d snippet was not activated due to an error.', '%d snippets were not activated due to errors.', $error_count, 'insert-headers-and-footers' ),
|
||||
$error_count
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $_GET['disabled'] ) ) {
|
||||
$count = absint( $_GET['disabled'] );
|
||||
$notice = sprintf( /* translators: %d - Deactivated snippets count. */
|
||||
_n( '%d snippet was successfully deactivated.', '%d snippets were successfully deactivated.', $count, 'insert-headers-and-footers' ),
|
||||
$count
|
||||
);
|
||||
}
|
||||
// phpcs:enable WordPress.Security.NonceVerification
|
||||
|
||||
if ( isset( $error_count ) && isset( $notice ) ) {
|
||||
$this->set_error_message( $notice );
|
||||
} elseif ( isset( $notice ) ) {
|
||||
$this->set_success_message( $notice );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On the deactivated snippets view, show a notice explaining that this view shows the snippets that have been
|
||||
* automatically disabled due to throwing an error and highlight the error logging option, if disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_show_deactivated_notice() {
|
||||
if ( ! isset( $_GET['view'] ) || 'has_error' !== $_GET['view'] ) { // phpcs:ignore WordPress.Security.NonceVerification
|
||||
return;
|
||||
}
|
||||
// Let's see if error logging is enabled.
|
||||
$logging_enabled = wpcode()->settings->get_option( 'error_logging' );
|
||||
$button_text = esc_html__( 'Enable Error Logging', 'insert-headers-and-footers' );
|
||||
$button_url = add_query_arg(
|
||||
array(
|
||||
'page' => 'wpcode-settings',
|
||||
'view' => 'errors',
|
||||
),
|
||||
$this->admin_url( 'admin.php' )
|
||||
);
|
||||
|
||||
?>
|
||||
<div class="info fade notice">
|
||||
<p>
|
||||
<?php esc_html_e( 'This view lists your snippets that threw errors. Some of the snippets may have also been automatically disabled due to potentially preventing you from accessing the admin.', 'insert-headers-and-footers' ); ?>
|
||||
<a href="<?php echo esc_url( wpcode_utm_url( 'https://wpcode.com/docs/php-error-handling-safe-mode/', 'snippet-deactivated-notice', 'deactivated-list' ) ); ?>" target="_blank" rel="noopener noreferrer">
|
||||
<?php esc_html_e( 'Learn More', 'insert-headers-and-footers' ); ?>
|
||||
</a>
|
||||
</p>
|
||||
<?php
|
||||
if ( ! $logging_enabled ) {
|
||||
?>
|
||||
<p>
|
||||
<?php esc_html_e( 'In order to get more info about the errors please consider enabling error logging.', 'insert-headers-and-footers' ); ?>
|
||||
</p>
|
||||
<p>
|
||||
<a href="<?php echo esc_url( $button_url ); ?>" class="button button-primary">
|
||||
<?php echo esc_html( $button_text ); ?>
|
||||
</a>
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the per page option to the snippets list screen.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_per_page_option() {
|
||||
add_screen_option(
|
||||
'per_page',
|
||||
array(
|
||||
'label' => esc_html__( 'Number of snippets per page:', 'insert-headers-and-footers' ),
|
||||
'option' => 'wpcode_snippets_per_page',
|
||||
'default' => 20,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the last updated column by default.
|
||||
*
|
||||
* @param array $hidden The hidden columns.
|
||||
* @param WP_Screen $screen The current screen.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function hide_columns( $hidden, $screen ) {
|
||||
$hidden[] = 'updated';
|
||||
$hidden[] = 'id';
|
||||
$hidden[] = 'shortcode';
|
||||
$hidden[] = 'code_type';
|
||||
|
||||
return $hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for the admin JS localization.
|
||||
*
|
||||
* @param array $data The data to be localized.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function prepare_admin_js_localization_data( $data ) {
|
||||
|
||||
$data['blocks_title'] = __( 'Blocks snippets is a Pro Feature', 'insert-headers-and-footers' );
|
||||
$data['blocks_description'] = __( 'Upgrade to PRO today and unlock building snippets using the Gutenberg Block Editor. Create templates using blocks and use the full power of WPCode to insert them in your site.', 'insert-headers-and-footers' );
|
||||
$data['blocks_snippet_upgrade_url'] = wpcode_utm_url( 'https://wpcode.com/lite/', 'code_type', 'blocks', 'modal' );
|
||||
$data['button_text'] = __( 'Upgrade to PRO', 'insert-headers-and-footers' );
|
||||
$data['scss_title'] = __( 'SCSS snippets is a Pro Feature', 'insert-headers-and-footers' );
|
||||
$data['scss_description'] = __( 'Upgrade to PRO today and unlock editing snippets using SCSS code with optimized compiling directly in the WordPress admin.', 'insert-headers-and-footers' );
|
||||
$data['scss_snippet_upgrade_url'] = wpcode_utm_url( 'https://wpcode.com/lite/', 'code_type', 'scss', 'modal' );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $screen_settings Screen settings.
|
||||
* @param WP_Screen $screen WP_Screen object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function add_custom_screen_option( $screen_settings, $screen ) {
|
||||
|
||||
$order_by = get_user_option( 'wpcode_snippets_order_by' );
|
||||
$order = get_user_option( 'wpcode_snippets_order' );
|
||||
if ( empty( $order_by ) ) {
|
||||
$order_by = 'ID';
|
||||
}
|
||||
if ( empty( $order ) ) {
|
||||
$order = 'desc';
|
||||
}
|
||||
|
||||
// Pick which column to order by, title, date or last updated using a select.
|
||||
$screen_settings .= '<h5>' . esc_html__( 'Order Snippets By', 'insert-headers-and-footers' ) . '</h5>';
|
||||
$screen_settings .= '<fieldset>';
|
||||
$screen_settings .= '<legend class="screen-reader-text">' . esc_html__( 'Order snippets by', 'insert-headers-and-footers' ) . '</legend>';
|
||||
// Use dropdown to choose the column to order by.
|
||||
$screen_settings .= '<label for="wpcode_screen_order_by">';
|
||||
$screen_settings .= '<select name="wpcode_screen_order_by" id="wpcode_screen_order_by">';
|
||||
$screen_settings .= '<option value="title" ' . selected( $order_by, 'title', false ) . '>' . esc_html__( 'Name', 'insert-headers-and-footers' ) . '</option>';
|
||||
$screen_settings .= '<option value="ID" ' . selected( $order_by, 'ID', false ) . '>' . esc_html__( 'Created', 'insert-headers-and-footers' ) . '</option>';
|
||||
$screen_settings .= '<option value="last_updated" ' . selected( $order_by, 'last_updated', false ) . '>' . esc_html__( 'Last Updated', 'insert-headers-and-footers' ) . '</option>';
|
||||
$screen_settings .= '<option value="priority" ' . selected( $order_by, 'priority', false ) . '>' . esc_html__( 'Priority', 'insert-headers-and-footers' ) . '</option>';
|
||||
$screen_settings .= '</select>';
|
||||
$screen_settings .= '</label>';
|
||||
// Display a dropdown to choose the order.
|
||||
$screen_settings .= '<label for="wpcode_screen_order">';
|
||||
$screen_settings .= '<select name="wpcode_screen_order" id="wpcode_screen_order">';
|
||||
$screen_settings .= '<option value="asc" ' . selected( $order, 'asc', false ) . '>' . esc_html__( 'Ascending', 'insert-headers-and-footers' ) . '</option>';
|
||||
$screen_settings .= '<option value="desc" ' . selected( $order, 'desc', false ) . '>' . esc_html__( 'Descending', 'insert-headers-and-footers' ) . '</option>';
|
||||
$screen_settings .= '</select>';
|
||||
$screen_settings .= '</label>';
|
||||
$screen_settings .= '</fieldset>';
|
||||
|
||||
return $screen_settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the duplicated parameter from the URL.
|
||||
*
|
||||
* @param array $args The arguments that should be removed from the URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function remove_query_arg_from_url( $args ) {
|
||||
$args[] = 'duplicated';
|
||||
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin page for the Duplicator tool.
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for the Duplicator admin page.
|
||||
*/
|
||||
class WPCode_Admin_Page_Duplicator extends WPCode_Admin_Page {
|
||||
|
||||
/**
|
||||
* The page slug to be used when adding the submenu.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $page_slug = 'wpcode-duplicator';
|
||||
|
||||
/**
|
||||
* The action used for the nonce.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $action = 'wpcode-duplicator';
|
||||
|
||||
/**
|
||||
* The nonce name field.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $nonce_name = 'wpcode-duplicator_nonce';
|
||||
|
||||
/**
|
||||
* Call this just to set the page title translatable.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->page_title = 'Secure Backups';
|
||||
$this->menu_title = 'Secure Backups';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hook on admin init just for this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_hooks() {
|
||||
add_action( 'admin_init', array( $this, 'maybe_redirect_to_duplicator' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to hide default header on this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the Duplicator page if the plugin is active.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_redirect_to_duplicator() {
|
||||
if ( class_exists( 'Duplicator\Lite\Requirements' ) ) {
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=duplicator' ) );
|
||||
exit;
|
||||
} elseif ( class_exists( 'Duplicator\Pro\Requirements' ) ) {
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=duplicator-pro' ) );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The page output.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_content() {
|
||||
?>
|
||||
<div class="wpcode-plugin-page wpcode-plugin-page-duplicator">
|
||||
<div class="wpcode-plugin-page-image">
|
||||
<?php wpcode_icon( 'duplicator', 90, 90, '198 55 90 396' ); ?>
|
||||
</div>
|
||||
<div class="wpcode-plugin-page-title">
|
||||
<h1>Protect Your Website with Secure WordPress Backups</h1>
|
||||
<p>
|
||||
<?php esc_html_e( 'Duplicator offers cloud WordPress backups with military-grade encryption. Automatically backup your entire WordPress site to secure cloud storage.', 'insert-headers-and-footers' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
<section class="wpcode-plugin-screenshot">
|
||||
<div class="wpcode-plugin-screenshot-image">
|
||||
<img src="<?php echo esc_url( WPCODE_PLUGIN_URL ); // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage ?>admin/images/duplicator.png" alt="<?php esc_attr_e( 'Duplicator Screenshot', 'insert-headers-and-footers' ); ?>"/>
|
||||
<a href="<?php echo esc_url( WPCODE_PLUGIN_URL ); ?>admin/images/duplicator.png" data-lity>
|
||||
<?php wpcode_icon( 'search', 16, 16 ); ?>
|
||||
</a>
|
||||
</div>
|
||||
<ul>
|
||||
<li><?php esc_html_e( 'Automatic Website Backups Made Easy.', 'insert-headers-and-footers' ); ?></li>
|
||||
<li><?php esc_html_e( 'Secure Cloud Storage Integration (Google Drive, AWS, Dropbox, and more).', 'insert-headers-and-footers' ); ?></li>
|
||||
<li><?php esc_html_e( '1-Click Restore from Recovery Points.', 'insert-headers-and-footers' ); ?></li>
|
||||
<li><?php esc_html_e( 'Website Cloning and Migration.', 'insert-headers-and-footers' ); ?></li>
|
||||
<li><?php esc_html_e( 'Used by 1.5 Million websites.', 'insert-headers-and-footers' ); ?></li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="wpcode-plugin-step wpcode-plugin-step-install">
|
||||
<aside class="wpcode-plugin-page-step-num">
|
||||
<?php wpcode_icon( 'step-1', 50, 50, '0 0 100 100' ); ?>
|
||||
<i class="wpcode-plugin-page-step-loader wpcode-plugin-page-step-loader-hidden"></i>
|
||||
</aside>
|
||||
<div>
|
||||
<h2>
|
||||
<?php
|
||||
printf(
|
||||
// translators: %s is the plugin name.
|
||||
esc_html__( 'Install and Activate %s', 'insert-headers-and-footers' ),
|
||||
'Duplicator'
|
||||
)
|
||||
?>
|
||||
</h2>
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
// translators: %s is the plugin name.
|
||||
esc_html__( 'Install %s from the WordPress.org plugin repository.', 'insert-headers-and-footers' ),
|
||||
'Duplicator'
|
||||
)
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
// Let's check if you can install plugins on this site.
|
||||
if ( current_user_can( 'install_plugins' ) && wp_is_file_mod_allowed( 'install_plugins' ) ) {
|
||||
?>
|
||||
<button class="wpcode-button wpcode-button-install-plugin" data-slug="duplicator">
|
||||
<?php
|
||||
printf(
|
||||
// translators: %s is the plugin name.
|
||||
esc_html__( 'Install %s', 'insert-headers-and-footers' ),
|
||||
'Duplicator'
|
||||
);
|
||||
?>
|
||||
</button>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<p>
|
||||
<?php esc_html_e( 'Please ask your website administrator to install Duplicator.', 'insert-headers-and-footers' ); ?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* For this page we output a title and the save button.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header_bottom() {
|
||||
}
|
||||
}
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
/**
|
||||
* File editor page.
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for the file editor page.
|
||||
*/
|
||||
class WPCode_Admin_Page_File_Editor extends WPCode_Admin_Page {
|
||||
|
||||
/**
|
||||
* The page slug.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $page_slug = 'wpcode-file-editor';
|
||||
|
||||
/**
|
||||
* The default view.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $view = 'adstxt';
|
||||
|
||||
/**
|
||||
* The capability required to view this page.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $capability = 'wpcode_file_editor';
|
||||
|
||||
/**
|
||||
* WPCode_Admin_Page_File_Editor constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->page_title = __( 'File Editor', 'insert-headers-and-footers' );
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add codemirror settings specific to the needs for this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_hooks() {
|
||||
// Add the codemirror settings.
|
||||
add_filter( 'wpcode_editor_config', array( $this, 'editor_config' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the page content.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_content() {
|
||||
$this->can_edit = true;
|
||||
echo '<div class="wpcode-blur-area" style="min-height: 700px">';
|
||||
$this->file_editor_area();
|
||||
echo '</div>';
|
||||
echo $this->get_pixel_overlay(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
/**
|
||||
* File editor area.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function file_editor_area() {
|
||||
$value = $this->get_value();
|
||||
?>
|
||||
<div class="wpcode-code-textarea" id="wpcode-edit-<?php echo esc_attr( $this->view ); ?>-area" style="max-width: 1000px">
|
||||
<div class="wpcode-flex">
|
||||
<div class="wpcode-column">
|
||||
<h2>
|
||||
<label for="wpcode_file_<?php echo esc_attr( $this->view ); ?>">
|
||||
<?php
|
||||
printf(
|
||||
// Translators: %s is the name of the file.
|
||||
esc_html__( '%s Editor', 'insert-headers-and-footers' ),
|
||||
esc_html( $this->views[ $this->view ] )
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
</h2>
|
||||
</div>
|
||||
<div class="wpcode-column">
|
||||
<div class="wpcode-input-select">
|
||||
<label for="<?php echo esc_attr( 'wpcode_file_' . $this->view . '[enabled]' ); ?>">
|
||||
<?php esc_html_e( 'Enable file output', 'insert-headers-and-footers' ); ?>
|
||||
</label>
|
||||
<?php
|
||||
echo $this->get_checkbox_toggle( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
$value['enabled'],
|
||||
esc_attr( 'wpcode_file_' . $this->view . '[enabled]' )
|
||||
)
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<textarea name="wpcode_file_<?php echo esc_attr( $this->view ); ?>[content]" id="wpcode_file_<?php echo esc_attr( $this->view ); ?>" class="widefat" rows="8"><?php echo esc_textarea( $value['content'] ); ?></textarea>
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
// Translators: %s is the name of the file.
|
||||
esc_html__( 'Use this area to edit your %s file.', 'insert-headers-and-footers' ),
|
||||
esc_html( $this->views[ $this->view ] )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
// Translators: %1$s is the opening link tag, %2$s is the closing link tag.
|
||||
esc_html__( 'The file contents above will be used to generated a dynamic file. There is no physical file created on your server. %1$sLearn more%2$s.', 'insert-headers-and-footers' ),
|
||||
'<a href="' . esc_url( wpcode_utm_url( 'https://wpcode.com/docs/file-editor/', 'file-editor', 'docs', 'learn-more' ) ) . '" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
wp_nonce_field( 'wpcode-edit-' . $this->view, 'wpcode-edit-' . $this->view . '-nonce' );
|
||||
|
||||
// If we need to add page-specific content we can do this here.
|
||||
if ( method_exists( $this, 'output_view_' . $this->view ) ) {
|
||||
call_user_func( array( $this, 'output_view_' . $this->view ) );
|
||||
}
|
||||
|
||||
?>
|
||||
<button class="wpcode-button" type="submit" <?php echo $this->can_edit ? '' : 'disabled'; ?>>
|
||||
<?php esc_html_e( 'Save Changes', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<a href="<?php echo esc_url( home_url() . '/' . $this->views[ $this->view ] ); ?>" class="wpcode-button wpcode-button-secondary" target="_blank" rel="noopener noreferrer">
|
||||
<?php esc_html_e( 'View File', 'insert-headers-and-footers' ); ?>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* For this page we output a menu.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header_bottom() {
|
||||
?>
|
||||
<ul class="wpcode-admin-tabs">
|
||||
<?php
|
||||
foreach ( $this->views as $slug => $label ) {
|
||||
$class = $this->view === $slug ? 'active' : '';
|
||||
?>
|
||||
<li>
|
||||
<a href="<?php echo esc_url( $this->get_view_link( $slug ) ); ?>" class="<?php echo esc_attr( $class ); ?>"><?php echo esc_html( $label ); ?></a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Page specific scripts. Hooked to 'admin_enqueue_scripts'.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_scripts() {
|
||||
$editor = new WPCode_Code_Editor( 'text' );
|
||||
|
||||
$editor->register_editor( 'wpcode_file_' . $this->view );
|
||||
$editor->init_editor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable all the codemirror settings for this page as we need a basic editor.
|
||||
*
|
||||
* @param array $config The WPCode editor config.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function editor_config( $config ) {
|
||||
|
||||
if ( 'serviceworkerjs' === $this->view ) {
|
||||
$config['type'] = 'text/javascript';
|
||||
} else {
|
||||
$config['type'] = 'shell';
|
||||
$config['codemirror'] = array();
|
||||
$config['showHint'] = 'false';
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output content specific to the robots.txt file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_robotstxt() {
|
||||
?>
|
||||
<p>
|
||||
<?php esc_html_e( 'Content added here will be appended to the robots.txt content generated by WordPress and other plugins.', 'insert-headers-and-footers' ); ?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup page-specific views.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setup_views() {
|
||||
$this->views = array(
|
||||
'adstxt' => 'ads.txt',
|
||||
'appadstxt' => 'app-ads.txt',
|
||||
'serviceworkerjs' => 'service-worker.js',
|
||||
'robotstxt' => 'robots.txt',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nothing to return by default.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_value() {
|
||||
return array(
|
||||
'enabled' => true,
|
||||
'content' => '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the overlay for the file editor page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_pixel_overlay() {
|
||||
|
||||
$text = '<p>' . esc_html__( 'Simplify your website management with the WPCode File Editor! Say goodbye to the hassle of manually editing files on your server.', 'insert-headers-and-footers' ) . '<p>';
|
||||
|
||||
$text .= sprintf(
|
||||
// translators: %1$s and %2$s are <u> tags.
|
||||
'<p>' . esc_html__( 'With this powerful tool, you can easily customize crucial files like %1$sads.txt%2$s, %1$sapp-ads.txt%2$s, %1$srobots.txt%2$s, and %1$sservice-worker.js%2$s right from your WordPress admin.', 'insert-headers-and-footers' ) . '</p>',
|
||||
'<u>',
|
||||
'</u>'
|
||||
);
|
||||
|
||||
|
||||
return self::get_upsell_box(
|
||||
__( 'File Editor is a PRO Feature', 'insert-headers-and-footers' ),
|
||||
$text,
|
||||
array(
|
||||
'text' => esc_html__( 'Upgrade to WPCode PRO', 'insert-headers-and-footers' ),
|
||||
'url' => esc_url( wpcode_utm_url( 'https://wpcode.com/lite/', 'file-editor', 'tab-' . $this->view, 'upgrade-to-pro' ) ),
|
||||
),
|
||||
array(
|
||||
'text' => esc_html__( 'Learn More about the File Editor', 'insert-headers-and-footers' ),
|
||||
'url' => esc_url( wpcode_utm_url( 'https://wpcode.com/docs/file-editor/', 'file-editor', 'tab-' . $this->view, 'learn-more' ) ),
|
||||
),
|
||||
array(
|
||||
esc_html__( 'No manual coding, no FTP', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Effortless integrations setup', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Reduce the number of plugins', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Prevent advertising fraud', 'insert-headers-and-footers' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
/**
|
||||
* The admin page for the snippet generator.
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WPCode_Admin_Page_Generator.
|
||||
*/
|
||||
class WPCode_Admin_Page_Generator extends WPCode_Admin_Page {
|
||||
|
||||
/**
|
||||
* The page slug.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $page_slug = 'wpcode-generator';
|
||||
|
||||
/**
|
||||
* Generator to show, if any.
|
||||
*
|
||||
* @var bool|string
|
||||
*/
|
||||
public $generator = false;
|
||||
|
||||
/**
|
||||
* Available generators.
|
||||
*
|
||||
* @var WPCode_Generator_Type[]
|
||||
*/
|
||||
public $generators;
|
||||
|
||||
/**
|
||||
* Set the code type for the editor on this page.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $code_type = 'php';
|
||||
|
||||
/**
|
||||
* Set the header title based on what is displayed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $header_title;
|
||||
|
||||
/**
|
||||
* Snippet if editing an existing, generated snippet.
|
||||
*
|
||||
* @var WPCode_Snippet
|
||||
*/
|
||||
public $snippet;
|
||||
|
||||
/**
|
||||
* The capability required to view this page.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $capability = 'wpcode_edit_php_snippets';
|
||||
|
||||
/**
|
||||
* Hide the generator menu item.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hide_menu = true;
|
||||
|
||||
/**
|
||||
* Call this just to set the page title translatable.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->page_title = __( 'Generator', 'insert-headers-and-footers' );
|
||||
$this->header_title = $this->page_title;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Page-specific hooks & logic.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_hooks() {
|
||||
$this->generators = wpcode()->generator()->get_all_generators();
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
// Let's see if we should display a generator.
|
||||
if ( isset( $_GET['generator'] ) ) {
|
||||
$generator = sanitize_text_field( wp_unslash( $_GET['generator'] ) );
|
||||
if ( array_key_exists( $generator, $this->generators ) ) {
|
||||
$this->generator = $generator;
|
||||
if ( isset( $this->generators[ $generator ]->code_type ) ) {
|
||||
$this->code_type = $this->generators[ $generator ]->code_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$snippet_id = isset( $_GET['snippet'] ) ? absint( $_GET['snippet'] ) : false;
|
||||
if ( $snippet_id ) {
|
||||
$this->snippet = new WPCode_Snippet( $snippet_id );
|
||||
if ( $this->snippet->get_post_data() ) {
|
||||
WPCode_Notice::add(
|
||||
sprintf(
|
||||
// Translators: gets replaced with the snippet title.
|
||||
__( 'You are now editing the generated snippet: "%s". Updating the snippet will override any edits you made to the code.', 'insert-headers-and-footers' ),
|
||||
$this->snippet->get_title()
|
||||
),
|
||||
'warning'
|
||||
);
|
||||
} else {
|
||||
unset( $this->snippet );
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
if ( $this->generator ) {
|
||||
// Translators: gets replaced with the generator name.
|
||||
$this->header_title = sprintf( __( '%s Generator', 'insert-headers-and-footers' ), $this->generators[ $this->generator ]->get_title() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the content of the page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_content() {
|
||||
if ( $this->generator ) {
|
||||
$this->show_generator();
|
||||
} else {
|
||||
$this->show_generators_list();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the list of generators with categories.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function show_generators_list() {
|
||||
$categories = wpcode()->generator()->get_categories();
|
||||
?>
|
||||
<div class="wpcode-items-metabox wpcode-metabox">
|
||||
<?php $this->get_items_list_sidebar( $categories, __( 'All Generators', 'insert-headers-and-footers' ), __( 'Search Generators', 'insert-headers-and-footers' ) ); ?>
|
||||
<div class="wpcode-items-list">
|
||||
<ul class="wpcode-items-list-category">
|
||||
<?php
|
||||
foreach ( $this->generators as $generator ) {
|
||||
$url = add_query_arg(
|
||||
array(
|
||||
'page' => $this->page_slug,
|
||||
'generator' => $generator->get_name(),
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
);
|
||||
$button_1 = array(
|
||||
'tag' => 'a',
|
||||
'url' => $url,
|
||||
'text' => __( 'Generate', 'insert-headers-and-footers' ),
|
||||
);
|
||||
$this->get_list_item( $generator->get_name(), $generator->get_title(), $generator->get_description(), $button_1, array(), $generator->get_categories() );
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the generator based on the param.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function show_generator() {
|
||||
$generator = $this->generators[ $this->generator ];
|
||||
$tabs = $generator->get_tabs();
|
||||
$snippet_data = array();
|
||||
if ( isset( $this->snippet ) ) {
|
||||
$snippet_data = $this->snippet->get_generator_data();
|
||||
}
|
||||
?>
|
||||
<form id="wpcode_generator_form">
|
||||
<div class="wpcode-items-metabox wpcode-metabox">
|
||||
<div class="wpcode-items-sidebar">
|
||||
<ul class="wpcode-items-categories-list wpcode-items-tabs">
|
||||
<?php
|
||||
$selected = key( $tabs );
|
||||
foreach ( $tabs as $tab_id => $tab ) {
|
||||
$class = $tab_id === $selected ? 'wpcode-active' : '';
|
||||
?>
|
||||
<li>
|
||||
<button type="button" class="<?php echo esc_attr( $class ); ?>" data-category="<?php echo esc_attr( $tab_id ); ?>"><?php echo esc_html( $tab['label'] ); ?></button>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="wpcode-items-list">
|
||||
<?php
|
||||
foreach ( $tabs as $tab_id => $tab ) {
|
||||
$style = $selected === $tab_id ? '' : 'display:none;';
|
||||
?>
|
||||
<div class="wpcode-form-tab" data-tab="<?php echo esc_attr( $tab_id ); ?>" style="<?php echo esc_attr( $style ); ?>">
|
||||
<?php $generator->render_tab( $tab_id, $snippet_data ); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="wpcode-generator-actions">
|
||||
<?php wp_nonce_field( 'wpcode_generate', 'nonce', false ); ?>
|
||||
<input type="hidden" name="type" value="<?php echo esc_attr( $this->generator ); ?>"/>
|
||||
<input type="hidden" name="action" value="wpcode_generate_snippet"/>
|
||||
<button type="submit" class="wpcode-button wpcode-button-secondary" id="wpcode-generator-update-code"><?php esc_html_e( 'Update code', 'insert-headers-and-footers' ); ?></button>
|
||||
<?php if ( ! empty( $this->snippet ) ) { ?>
|
||||
<input type="hidden" name="snippet_id" value="<?php echo absint( $this->snippet->get_id() ); ?>"/>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="wpcode-generator-preview">
|
||||
<div class="wpcode-generator-preview-header">
|
||||
<h2><?php esc_html_e( 'Code Preview', 'insert-headers-and-footers' ); ?></h2>
|
||||
<?php
|
||||
if ( ! empty( $this->snippet ) ) {
|
||||
?>
|
||||
<button type="button" class="wpcode-button" id="wpcode-generator-use-snippet"><?php esc_html_e( 'Update Snippet', 'insert-headers-and-footers' ); ?></button>
|
||||
<?php } else { ?>
|
||||
<button type="button" class="wpcode-button" id="wpcode-generator-use-snippet"><?php esc_html_e( 'Use Snippet', 'insert-headers-and-footers' ); ?></button>
|
||||
<?php } ?>
|
||||
<button class="wpcode-button wpcode-button-icon wpcode-button-secondary wpcode-copy-target" data-target="#wpcode_generator_code_preview" type="button">
|
||||
<span class="wpcode-default-icon"><?php wpcode_icon( 'copy', 16, 16 ); ?></span><span class="wpcode-success-icon"><?php wpcode_icon( 'check', 16, 13 ); ?></span> <?php echo esc_html_x( 'Copy Code', 'Copy to clipboard', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<textarea id="wpcode_generator_code_preview"><?php echo esc_textarea( $generator->get_snippet_code() ); ?></textarea>
|
||||
</div>
|
||||
<script type="text/template" id="wpcode-generator-repeater-row">
|
||||
<?php $this->repeater_group_template(); ?>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* The bottom part of the header.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header_bottom() {
|
||||
?>
|
||||
<div class="wpcode-column">
|
||||
<h1><?php echo esc_html( $this->header_title ); ?></h1>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* The template for the repeater row.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function repeater_group_template() {
|
||||
?>
|
||||
<div class="wpcode-repeater-group">
|
||||
<button type="button" class="wpcode-button wpcode-button-secondary wpcode-remove-row"><?php esc_html_e( 'Remove Row', 'insert-headers-and-footers' ); ?></button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Add page-specific scripts.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_scripts() {
|
||||
if ( ! $this->generator ) {
|
||||
return;
|
||||
}
|
||||
$editor = new WPCode_Code_Editor( $this->code_type );
|
||||
$editor->set_setting( 'readOnly', 'nocursor' );
|
||||
$editor->register_editor( 'wpcode_generator_code_preview' );
|
||||
$editor->init_editor();
|
||||
|
||||
wp_enqueue_script( 'jquery-ui-autocomplete' );
|
||||
wp_enqueue_media();
|
||||
}
|
||||
}
|
||||
+360
@@ -0,0 +1,360 @@
|
||||
<?php
|
||||
/**
|
||||
* Headers & Footers admin page.
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for the headers & footers admin page.
|
||||
*/
|
||||
class WPCode_Admin_Page_Headers_Footers extends WPCode_Admin_Page {
|
||||
|
||||
use WPCode_Revisions_Display_Lite;
|
||||
use WPCode_WPConsent_Notice;
|
||||
|
||||
/**
|
||||
* The page slug to be used when adding the submenu.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $page_slug = 'wpcode-headers-footers';
|
||||
|
||||
/**
|
||||
* The action used for the nonce.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $action = 'insert-headers-and-footers';
|
||||
|
||||
/**
|
||||
* If the page should be a submenu of Settings instead of wpcode.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $settings_submenu = false;
|
||||
|
||||
/**
|
||||
* The nonce name field.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $nonce_name = 'insert-headers-and-footers_nonce';
|
||||
|
||||
/**
|
||||
* The capability required to view this page.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $capability = 'wpcode_edit_html_snippets';
|
||||
|
||||
/**
|
||||
* Call this just to set the page title translatable.
|
||||
*/
|
||||
public function __construct() {
|
||||
if ( wpcode()->settings->get_option( 'headers_footers_mode' ) ) {
|
||||
$this->settings_submenu = true;
|
||||
}
|
||||
$this->page_title = __( 'Header & Footer', 'insert-headers-and-footers' );
|
||||
parent::__construct();
|
||||
|
||||
add_action( 'wpcode_admin_page_content_wpcode-headers-footers', array( $this, 'revisions_box' ), 260 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the submenu page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_page() {
|
||||
if ( $this->settings_submenu ) {
|
||||
add_options_page(
|
||||
$this->menu_title,
|
||||
$this->page_title,
|
||||
'wpcode_edit_snippets',
|
||||
$this->page_slug,
|
||||
array(
|
||||
wpcode()->admin_page_loader,
|
||||
'admin_menu_page',
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
parent::add_page();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hook on admin init just for this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_hooks() {
|
||||
// The Header & Footer content is always live, so editing it requires activation rights too.
|
||||
$this->can_edit = current_user_can( 'unfiltered_html', 'wpcode-editor' ) && current_user_can( 'wpcode_activate_snippets' );
|
||||
add_action( 'admin_init', array( $this, 'submit_listener' ) );
|
||||
$this->process_message();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process messages specific to this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process_message() {
|
||||
// phpcs:disable WordPress.Security.NonceVerification
|
||||
if ( ! isset( $_GET['message'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$messages = array(
|
||||
1 => __( 'Headers & Footers mode activated. Use the toggle next to the Save Changes button to disable it at any time.', 'insert-headers-and-footers' ),
|
||||
2 => __( 'Headers & Footers mode deactivated, if you wish to switch back please use the option on the settings page.', 'insert-headers-and-footers' ),
|
||||
);
|
||||
$message = absint( $_GET['message'] );
|
||||
// phpcs:enable WordPress.Security.NonceVerification
|
||||
|
||||
if ( ! isset( $messages[ $message ] ) ) {
|
||||
return;
|
||||
}
|
||||
$this->set_success_message( $messages[ $message ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap this page in a form tag.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output() {
|
||||
if ( ! $this->can_edit ) {
|
||||
$this->set_error_message( __( 'Sorry, you only have read-only access to this page. Ask your administrator for assistance editing.', 'insert-headers-and-footers' ) );
|
||||
$headers_footers_mode = wpcode()->settings->get_option( 'headers_footers_mode' );
|
||||
// If in headers & footers mode allow them to update to disable the simple mode.
|
||||
if ( ! $headers_footers_mode ) {
|
||||
// If the user can't edit the values just don't load form at all.
|
||||
parent::output();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<form action="<?php echo esc_url( $this->get_page_action_url() ); ?>" method="post">
|
||||
<?php parent::output(); ?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* The headers & footers page output.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_content() {
|
||||
|
||||
$this->notice_wpconsent();
|
||||
|
||||
$header_desc = sprintf(
|
||||
/* translators: %s: The `<head>` tag */
|
||||
esc_html__( 'These scripts will be printed in the %s section.', 'insert-headers-and-footers' ),
|
||||
'<code><head></code>'
|
||||
);
|
||||
$body_desc = sprintf(
|
||||
/* translators: %s: The `<head>` tag */
|
||||
esc_html__( 'These scripts will be printed just below the opening %s tag.', 'insert-headers-and-footers' ),
|
||||
'<code><body></code>'
|
||||
);
|
||||
$footer_desc = sprintf(
|
||||
/* translators: %s: The `</body>` tag */
|
||||
esc_html__( 'These scripts will be printed above the closing %s tag.', 'insert-headers-and-footers' ),
|
||||
'<code></body></code>'
|
||||
);
|
||||
$this->textarea_field( 'header', __( 'Header', 'insert-headers-and-footers' ), $header_desc );
|
||||
if ( $this->body_supported() ) {
|
||||
$this->textarea_field( 'body', __( 'Body', 'insert-headers-and-footers' ), $body_desc );
|
||||
}
|
||||
$this->textarea_field( 'footer', __( 'Footer', 'insert-headers-and-footers' ), $footer_desc );
|
||||
wp_nonce_field( $this->action, $this->nonce_name );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the website supports wp_body_open.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function body_supported() {
|
||||
return function_exists( 'wp_body_open' ) && version_compare( get_bloginfo( 'version' ), '5.2', '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard output for a code input field.
|
||||
*
|
||||
* @param string $option The option name as stored in the DB.
|
||||
* @param string $title The title of the input (also used as label).
|
||||
* @param string $desc The description that shows up under the field.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function textarea_field( $option, $title, $desc ) {
|
||||
$value = wp_unslash( $this->get_option( $option ) );
|
||||
?>
|
||||
<div class="wpcode-code-textarea" id="wpcode-global-<?php echo esc_attr( $option ); ?>">
|
||||
<h2><label for="ihaf_insert_<?php echo esc_attr( $option ); ?>"><?php echo esc_html( $title ); ?></label>
|
||||
</h2>
|
||||
<textarea name="ihaf_insert_<?php echo esc_attr( $option ); ?>" id="ihaf_insert_<?php echo esc_attr( $option ); ?>" class="widefat" rows="8" <?php disabled( ! $this->can_edit ); ?>><?php echo esc_html( $value ); ?></textarea>
|
||||
<p>
|
||||
<?php echo wp_kses( $desc, array( 'code' => array() ) ); ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of an option.
|
||||
*
|
||||
* @param string $option The option name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_option( $option ) {
|
||||
return get_option( 'ihaf_insert_' . $option );
|
||||
}
|
||||
|
||||
/**
|
||||
* For this page we output a title and the save button.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header_bottom() {
|
||||
$headers_footers_mode = wpcode()->settings->get_option( 'headers_footers_mode' );
|
||||
$button_disabled = ! $this->can_edit && ! $headers_footers_mode ? 'disabled' : '';
|
||||
?>
|
||||
<div class="wpcode-column">
|
||||
<h1><?php esc_html_e( 'Global Header and Footer', 'insert-headers-and-footers' ); ?></h1>
|
||||
</div>
|
||||
<div class="wpcode-column">
|
||||
<?php $this->get_submenu_toggle(); ?>
|
||||
<button class="wpcode-button" type="submit" <?php echo esc_attr( $button_disabled ); ?>>
|
||||
<?php esc_html_e( 'Save Changes', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the toggle to disable submenu mode.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function get_submenu_toggle() {
|
||||
if ( ! $this->settings_submenu ) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="wpcode-simple-mode-container-button">
|
||||
<label for="headers_footers_mode" class="wpcode-status-text"><?php esc_html_e( 'Simple mode', 'insert-headers-and-footers' ); ?></label>
|
||||
<?php echo $this->get_checkbox_toggle( true, 'headers_footers_mode' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Page specific scripts. Hooked to 'admin_enqueue_scripts'.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_scripts() {
|
||||
$editor = new WPCode_Code_Editor();
|
||||
|
||||
$editor->register_editor( 'ihaf_insert_header' );
|
||||
$editor->register_editor( 'ihaf_insert_footer' );
|
||||
if ( $this->body_supported() ) {
|
||||
$editor->register_editor( 'ihaf_insert_body' );
|
||||
}
|
||||
$editor->init_editor();
|
||||
}
|
||||
|
||||
/**
|
||||
* If the form is submitted attempt to save the values.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function submit_listener() {
|
||||
if ( ! isset( $_REQUEST[ $this->nonce_name ] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST[ $this->nonce_name ] ), $this->action ) ) {
|
||||
// Nonce is missing, so we're not even going to try.
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->can_edit && isset( $_REQUEST['ihaf_insert_header'] ) && isset( $_REQUEST['ihaf_insert_footer'] ) ) {
|
||||
// If they are not allowed to edit the page these should not be processed but we still allow them to save to disable the simple mode.
|
||||
update_option( 'ihaf_insert_header', $_REQUEST['ihaf_insert_header'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
update_option( 'ihaf_insert_footer', $_REQUEST['ihaf_insert_footer'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
update_option( 'ihaf_insert_body', isset( $_REQUEST['ihaf_insert_body'] ) ? $_REQUEST['ihaf_insert_body'] : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
|
||||
// Clear the cache.
|
||||
if ( apply_filters( 'wpcode_clear_cache_on_global_save', true ) ) {
|
||||
wpcode_clear_all_plugins_page_cache( 'global' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( wpcode()->settings->get_option( 'headers_footers_mode' ) && ! isset( $_REQUEST['headers_footers_mode'] ) ) {
|
||||
wpcode()->settings->update_option( 'headers_footers_mode', false );
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
array(
|
||||
'page' => $this->page_slug,
|
||||
'message' => 2,
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->set_success_message( __( 'Settings Saved. Please don\'t forget to clear the site cache if you are using a cache plugin, so that the changes will be reflected for all users.', 'insert-headers-and-footers' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Use a different base url when the headers_footers_mode is enabled.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_page_action_url() {
|
||||
$url = parent::get_page_action_url();
|
||||
|
||||
if ( ! wpcode()->settings->get_option( 'headers_footers_mode' ) ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
return str_replace( 'admin.php', 'options-general.php', $url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the revisions box.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function revisions_box() {
|
||||
$html = $this->code_revisions_list_with_notice(
|
||||
esc_html__( 'Code Revisions is a Pro Feature', 'insert-headers-and-footers' ),
|
||||
sprintf(
|
||||
'<p>%s</p>',
|
||||
esc_html__( 'Upgrade to WPCode Pro today and start tracking revisions and see exactly who, when and which changes were made to global Headers & Footers scripts.', 'insert-headers-and-footers' )
|
||||
),
|
||||
array(
|
||||
'text' => esc_html__( 'Upgrade to Pro and Unlock Revisions', 'insert-headers-and-footers' ),
|
||||
'url' => wpcode_utm_url( 'https://wpcode.com/lite/', 'headers-footers', 'revisions', 'upgrade-to-pro' ),
|
||||
),
|
||||
array(
|
||||
'text' => esc_html__( 'Learn more about all the features', 'insert-headers-and-footers' ),
|
||||
'url' => wpcode_utm_url( 'https://wpcode.com/lite/', 'headers-footers', 'revisions', 'features' ),
|
||||
)
|
||||
);
|
||||
|
||||
$this->metabox(
|
||||
__( 'Code Revisions', 'insert-headers-and-footers' ),
|
||||
$html,
|
||||
__( 'Easily switch back to a previous version of your global scripts.', 'insert-headers-and-footers' )
|
||||
);
|
||||
}
|
||||
}
|
||||
+246
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin page for the snippets library.
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* WPCode_Admin_Page_Library class.
|
||||
*/
|
||||
class WPCode_Admin_Page_Library extends WPCode_Admin_Page {
|
||||
|
||||
use WPCode_My_Library_Markup_Lite;
|
||||
/**
|
||||
* The page slug.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $page_slug = 'wpcode-library';
|
||||
/**
|
||||
* We always show the library on this page.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $show_library = true;
|
||||
|
||||
/**
|
||||
* The default view.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $view = 'library';
|
||||
|
||||
/**
|
||||
* The object used for loading data on this page.
|
||||
*
|
||||
* @var WPCode_Library
|
||||
*/
|
||||
protected $data_handler;
|
||||
|
||||
/**
|
||||
* The capability required to view this page.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $capability = 'wpcode_edit_php_snippets';
|
||||
|
||||
/**
|
||||
* Call this just to set the page title translatable.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->page_title = __( 'Library', 'insert-headers-and-footers' );
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup page-specific views.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setup_views() {
|
||||
$this->views = array(
|
||||
'library' => __( 'Snippets', 'insert-headers-and-footers' ),
|
||||
'my_library' => __( 'My Library', 'insert-headers-and-footers' ),
|
||||
'my_favorites' => __( 'My Favorites', 'insert-headers-and-footers' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add page-specific hooks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_hooks() {
|
||||
$this->process_message();
|
||||
add_action( 'admin_init', array( $this, 'maybe_add_from_library' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle grabbing snippets from the library.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_add_from_library() {
|
||||
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'wpcode_add_from_library' ) ) {
|
||||
return;
|
||||
}
|
||||
$library_id = isset( $_GET['snippet_library_id'] ) ? absint( $_GET['snippet_library_id'] ) : 0;
|
||||
|
||||
if ( empty( $library_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$snippet = $this->get_data_handler()->create_new_snippet( $library_id );
|
||||
|
||||
if ( $snippet ) {
|
||||
$url = add_query_arg(
|
||||
array(
|
||||
'page' => 'wpcode-snippet-manager',
|
||||
'snippet_id' => $snippet->get_id(),
|
||||
),
|
||||
$this->admin_url( 'admin.php' )
|
||||
);
|
||||
} else {
|
||||
$url = add_query_arg(
|
||||
array(
|
||||
'message' => 1,
|
||||
),
|
||||
remove_query_arg(
|
||||
array(
|
||||
'_wpnonce',
|
||||
'snippet_library_id',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
wp_safe_redirect( $url );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Markup for the Library page content.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_content() {
|
||||
|
||||
if ( method_exists( $this, 'output_view_' . $this->view ) ) {
|
||||
call_user_func( array( $this, 'output_view_' . $this->view ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ouptut the library content (default view).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_library() {
|
||||
$library_data = $this->get_data_handler()->get_data();
|
||||
$categories = $library_data['categories'];
|
||||
$snippets = $library_data['snippets'];
|
||||
|
||||
$this->get_library_markup( $categories, $snippets );
|
||||
$this->library_preview_modal_content();
|
||||
$this->library_connect_banner_template();
|
||||
}
|
||||
|
||||
/**
|
||||
* For this page we output a menu.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header_bottom() {
|
||||
?>
|
||||
<ul class="wpcode-admin-tabs">
|
||||
<?php
|
||||
foreach ( $this->views as $slug => $label ) {
|
||||
$class = $this->view === $slug ? 'active' : '';
|
||||
?>
|
||||
<li>
|
||||
<a href="<?php echo esc_url( $this->get_view_link( $slug ) ); ?>" class="<?php echo esc_attr( $class ); ?>"><?php echo esc_html( $label ); ?></a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Process messages specific to this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process_message() {
|
||||
// phpcs:disable WordPress.Security.NonceVerification
|
||||
if ( ! isset( $_GET['message'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$messages = array(
|
||||
1 => __( 'We encountered an error while trying to load the snippet data. Please try again.', 'insert-headers-and-footers' ),
|
||||
);
|
||||
$message = absint( $_GET['message'] );
|
||||
// phpcs:enable WordPress.Security.NonceVerification
|
||||
|
||||
if ( ! isset( $messages[ $message ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set_error_message( $messages[ $message ] );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Markup for the "My Library" page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_my_library() {
|
||||
$this->get_my_library_markup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Markup for the "My Library" page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_my_favorites() {
|
||||
$this->blurred_placeholder_items();
|
||||
// Show upsell.
|
||||
echo WPCode_Admin_Page::get_upsell_box( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
esc_html__( 'My Favorites is a PRO Feature', 'insert-headers-and-footers' ),
|
||||
'<p>' . esc_html__( 'Upgrade to WPCode PRO today and see the snippets you starred in the WPCode Library directly in the plugin.', 'insert-headers-and-footers' ) . '</p>',
|
||||
array(
|
||||
'text' => esc_html__( 'Upgrade to PRO and Unlock "My Favorites"', 'insert-headers-and-footers' ),
|
||||
'url' => esc_url( wpcode_utm_url( 'https://wpcode.com/lite/', 'library-page', 'my-favorites', 'upgrade-and-unlock' ) ),
|
||||
),
|
||||
array(
|
||||
'text' => esc_html__( 'Learn more about all the features', 'insert-headers-and-footers' ),
|
||||
'url' => esc_url( wpcode_utm_url( 'https://wpcode.com/lite/', 'library-page', 'my-favorites', 'features' ) ),
|
||||
),
|
||||
array(
|
||||
esc_html__( 'Load favorite snippets in the plugin', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Import snippets from the WPCode Library', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Save your snippets to the WPCode Library', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Set up new websites faster', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Easily implement features on multiple sites', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Edit snippets in the WPCode Library', 'insert-headers-and-footers' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data handler for this page.
|
||||
*
|
||||
* @return WPCode_Library
|
||||
*/
|
||||
public function get_data_handler() {
|
||||
if ( ! isset( $this->data_handler ) ) {
|
||||
$this->data_handler = wpcode()->library;
|
||||
}
|
||||
|
||||
return $this->data_handler;
|
||||
}
|
||||
|
||||
}
|
||||
+275
@@ -0,0 +1,275 @@
|
||||
<?php
|
||||
/**
|
||||
* Live Preview Admin Page.
|
||||
*
|
||||
* This page handles the split-screen CSS live preview interface.
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WPCode_Admin_Page_Live_Preview
|
||||
*/
|
||||
class WPCode_Admin_Page_Live_Preview extends WPCode_Admin_Page {
|
||||
|
||||
/**
|
||||
* The page slug to be used when adding the submenu.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $page_slug = 'wpcode-live-preview';
|
||||
|
||||
/**
|
||||
* Hide this page from the menu.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hide_menu = true;
|
||||
|
||||
/**
|
||||
* The snippet ID being previewed.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $snippet_id;
|
||||
|
||||
/**
|
||||
* The snippet instance.
|
||||
*
|
||||
* @var WPCode_Snippet
|
||||
*/
|
||||
private $snippet;
|
||||
|
||||
/**
|
||||
* The CSS code to preview.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $preview_css;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->page_title = __( 'Live CSS Preview', 'insert-headers-and-footers' );
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Page-specific hooks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_hooks() {
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
if ( ! isset( $_GET['snippet_id'] ) ) {
|
||||
wp_die( esc_html__( 'No snippet ID provided.', 'insert-headers-and-footers' ) );
|
||||
}
|
||||
|
||||
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'wpcode-live-preview' ) ) {
|
||||
wp_die( esc_html__( 'The link you followed has expired.', 'insert-headers-and-footers' ) );
|
||||
}
|
||||
|
||||
$this->snippet_id = absint( $_GET['snippet_id'] );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
if ( $this->snippet_id ? ! current_user_can( 'edit_post', $this->snippet_id ) : ! current_user_can( 'wpcode_edit_snippets' ) ) {
|
||||
wp_die( esc_html__( 'Sorry, you are not allowed to do that.', 'insert-headers-and-footers' ), '', array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
$this->snippet = wpcode_get_snippet( $this->snippet_id );
|
||||
|
||||
if ( ! $this->snippet ) {
|
||||
wp_die( esc_html__( 'Invalid snippet ID.', 'insert-headers-and-footers' ) );
|
||||
}
|
||||
|
||||
// Get the CSS to preview.
|
||||
$this->preview_css = $this->get_snippet_css();
|
||||
|
||||
// Store CSS in transient for the preview frame.
|
||||
$this->save_preview_css();
|
||||
|
||||
add_filter( 'wpcode_admin_js_data', array( $this, 'add_preview_data' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the page content.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_content() {
|
||||
$preview_url = add_query_arg(
|
||||
array(
|
||||
'wpcode_preview' => '1',
|
||||
'snippet_id' => $this->snippet_id,
|
||||
),
|
||||
home_url( '/' )
|
||||
);
|
||||
?>
|
||||
<div class="wpcode-live-preview-container">
|
||||
<div class="wpcode-live-preview-editor">
|
||||
<div class="wpcode-live-preview-editor-header">
|
||||
<h3><?php echo 'scss' === $this->snippet->get_code_type() ? esc_html__( 'SCSS Editor', 'insert-headers-and-footers' ) : esc_html__( 'CSS Editor', 'insert-headers-and-footers' ); ?></h3>
|
||||
<div class="wpcode-live-preview-device-toggles">
|
||||
<button type="button" class="wpcode-device-toggle wpcode-device-desktop wpcode-active" data-device="desktop" title="<?php esc_attr_e( 'Desktop View', 'insert-headers-and-footers' ); ?>">
|
||||
<?php wpcode_icon( 'desktop', 20, 20, '0 0 48 48' ); ?>
|
||||
</button>
|
||||
<button type="button" class="wpcode-device-toggle wpcode-device-tablet" data-device="tablet" title="<?php esc_attr_e( 'Tablet View', 'insert-headers-and-footers' ); ?>">
|
||||
<?php wpcode_icon( 'tablet', 20, 20, '2 1 20 20' ); ?>
|
||||
</button>
|
||||
<button type="button" class="wpcode-device-toggle wpcode-device-mobile" data-device="mobile" title="<?php esc_attr_e( 'Mobile View', 'insert-headers-and-footers' ); ?>">
|
||||
<?php wpcode_icon( 'mobile', 20, 20, '0 0 48 48' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="wpcode-live-preview-editor-area">
|
||||
<textarea id="wpcode-live-preview-css-editor" name="wpcode_live_preview_css"><?php echo esc_textarea( $this->preview_css ); ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="wpcode-live-preview-resizer" title="<?php esc_attr_e( 'Drag to resize the editor', 'insert-headers-and-footers' ); ?>"></div>
|
||||
<div class="wpcode-live-preview-iframe-wrapper wpcode-device-desktop">
|
||||
<div class="wpcode-live-preview-loading">
|
||||
<?php esc_html_e( 'Loading preview...', 'insert-headers-and-footers' ); ?>
|
||||
</div>
|
||||
<iframe id="wpcode-live-preview-frame" src="<?php echo esc_url( $preview_url ); ?>" title="<?php esc_attr_e( 'Live Preview', 'insert-headers-and-footers' ); ?>"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
<div class="wpcode-live-preview-actions">
|
||||
<img id="wpcode-live-preview-logo" class="wpcode-live-preview-logo" src="<?php echo esc_url( WPCODE_PLUGIN_URL . 'admin/images/wpcode-logo.png' ); ?>" alt="<?php esc_attr_e( 'WPCode', 'insert-headers-and-footers' ); ?>" />
|
||||
<button type="button" class="wpcode-button wpcode-button-secondary" id="wpcode-live-preview-discard">
|
||||
<?php esc_html_e( 'Discard & Exit', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<button type="button" class="wpcode-button" id="wpcode-live-preview-save">
|
||||
<?php esc_html_e( 'Save & Exit', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the header for this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header() {
|
||||
// Intentionally empty - no header for the live preview page.
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't output the standard footer for this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_footer() {
|
||||
// Intentionally empty - we don't want the standard footer overlays.
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue page-specific scripts.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_scripts() {
|
||||
// Determine the code type (CSS or SCSS).
|
||||
$code_type = $this->snippet ? $this->snippet->get_code_type() : 'css';
|
||||
|
||||
// The code editor.
|
||||
$code_editor = new WPCode_Code_Editor( $code_type );
|
||||
$code_editor->register_editor( 'wpcode-live-preview-css-editor' );
|
||||
$code_editor->init_editor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add preview-specific data to the JavaScript.
|
||||
*
|
||||
* @param array $data The existing data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_preview_data( $data ) {
|
||||
$data['livePreview'] = array(
|
||||
'snippetId' => $this->snippet_id,
|
||||
'editorId' => 'wpcode-live-preview-css-editor',
|
||||
'iframeId' => 'wpcode-live-preview-frame',
|
||||
'snippetUrl' => add_query_arg(
|
||||
array(
|
||||
'page' => 'wpcode-snippet-manager',
|
||||
'snippet_id' => $this->snippet_id,
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
),
|
||||
'hasChanges' => false,
|
||||
'exitConfirm' => __( 'You have unsaved changes. Are you sure you want to exit?', 'insert-headers-and-footers' ),
|
||||
'codeType' => $this->snippet ? $this->snippet->get_code_type() : 'css',
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the CSS/SCSS code to preview.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_snippet_css() {
|
||||
$user_id = get_current_user_id();
|
||||
$code_type = $this->snippet->get_code_type();
|
||||
|
||||
// For SCSS snippets, check for unsaved SCSS source first.
|
||||
if ( 'scss' === $code_type ) {
|
||||
$source_transient_key = "wpcode_preview_scss_source_{$user_id}_{$this->snippet_id}";
|
||||
$transient_source = get_transient( $source_transient_key );
|
||||
|
||||
if ( false !== $transient_source ) {
|
||||
return $transient_source;
|
||||
}
|
||||
} else {
|
||||
// For CSS snippets, check if there's unsaved CSS in the transient.
|
||||
$transient_key = "wpcode_preview_css_{$user_id}_{$this->snippet_id}";
|
||||
$transient_css = get_transient( $transient_key );
|
||||
|
||||
if ( false !== $transient_css ) {
|
||||
return $transient_css;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, get the code from the snippet.
|
||||
return $this->snippet->get_code();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the preview CSS to a transient.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function save_preview_css() {
|
||||
$user_id = get_current_user_id();
|
||||
$code_type = $this->snippet->get_code_type();
|
||||
|
||||
// For SCSS, store the source code in the source transient.
|
||||
// The compiled CSS will be generated client-side and stored separately.
|
||||
if ( 'scss' === $code_type ) {
|
||||
$source_transient_key = "wpcode_preview_scss_source_{$user_id}_{$this->snippet_id}";
|
||||
set_transient( $source_transient_key, $this->preview_css, HOUR_IN_SECONDS );
|
||||
} else {
|
||||
// For CSS, store directly.
|
||||
$transient_key = "wpcode_preview_css_{$user_id}_{$this->snippet_id}";
|
||||
set_transient( $transient_key, $this->preview_css, HOUR_IN_SECONDS );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a body class specific to the live preview page.
|
||||
*
|
||||
* @param string $body_class The existing body classes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function page_specific_body_class( $body_class ) {
|
||||
$body_class = parent::page_specific_body_class( $body_class );
|
||||
$body_class .= ' wpcode-live-preview-page';
|
||||
|
||||
return $body_class;
|
||||
}
|
||||
}
|
||||
|
||||
+919
@@ -0,0 +1,919 @@
|
||||
<?php
|
||||
/**
|
||||
* The Conversion Pixels page.
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WPCode_Admin_Page_Pixel.
|
||||
*/
|
||||
class WPCode_Admin_Page_Pixel extends WPCode_Admin_Page {
|
||||
|
||||
use WPCode_WPConsent_Notice;
|
||||
|
||||
/**
|
||||
* The page slug to be used when adding the submenu.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $page_slug = 'wpcode-pixel';
|
||||
|
||||
/**
|
||||
* Default view.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $view = 'facebook';
|
||||
|
||||
/**
|
||||
* The capability required to view this page.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $capability = 'wpcode_manage_conversion_pixels';
|
||||
|
||||
/**
|
||||
* Call this just to set the page title translatable.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->page_title = __( 'Conversion Pixels', 'insert-headers-and-footers' );
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Conversion Pixels page output.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_content() {
|
||||
$this->notice_wpconsent();
|
||||
if ( method_exists( $this, 'output_view_' . $this->view ) ) {
|
||||
echo '<div class="wpcode-blur-area">';
|
||||
call_user_func( array( $this, 'output_view_' . $this->view ) );
|
||||
echo '</div>';
|
||||
echo $this->get_pixel_overlay(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the overlay for the pixel settings.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_pixel_overlay() {
|
||||
|
||||
$text = sprintf(
|
||||
// translators: %1$s and %2$s are <u> tags.
|
||||
'<p>' . esc_html__( 'While you can always add pixels manually using code snippets, our Conversion Pixels addon helps you %1$ssave time%2$s while %1$sreducing errors%2$s. It lets you properly implement Facebook, Google, Pinterest, TikTok, Snapchat and OpenAI ads tracking with deep integrations for eCommerce events, interaction measurement, and more. This addon is available on WPCode Plus plan or higher.', 'insert-headers-and-footers' ) . '</p>',
|
||||
'<u>',
|
||||
'</u>'
|
||||
);
|
||||
|
||||
return self::get_upsell_box(
|
||||
esc_html__( 'Conversion Pixels Addon is a PRO Feature', 'insert-headers-and-footers' ),
|
||||
$text,
|
||||
array(
|
||||
'text' => esc_html__( 'Upgrade to WPCode PRO', 'insert-headers-and-footers' ),
|
||||
'url' => esc_url( wpcode_utm_url( 'https://wpcode.com/lite/', 'conversion-pixels', 'tab-' . $this->view, 'upgrade-to-pro' ) ),
|
||||
),
|
||||
array(),
|
||||
array(
|
||||
esc_html__( 'Seamless integration with WooCommerce, Easy Digital Downloads and MemberPress', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Works with Facebook, Google Ads, Pinterest, TikTok, Snapchat and OpenAI', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'No coding required', 'insert-headers-and-footers' ),
|
||||
esc_html__( '1-click setup for conversion tracking', 'insert-headers-and-footers' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup page-specific views.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setup_views() {
|
||||
$this->views = array(
|
||||
'facebook' => __( 'Facebook', 'insert-headers-and-footers' ),
|
||||
'google' => __( 'Google', 'insert-headers-and-footers' ),
|
||||
'pinterest' => __( 'Pinterest', 'insert-headers-and-footers' ),
|
||||
'tiktok' => __( 'TikTok', 'insert-headers-and-footers' ),
|
||||
'snapchat' => __( 'Snapchat', 'insert-headers-and-footers' ),
|
||||
'openai' => __( 'OpenAI', 'insert-headers-and-footers' ),
|
||||
'click_tracking' => __( 'Click Tracking', 'insert-headers-and-footers' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* For this page we output a menu.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header_bottom() {
|
||||
?>
|
||||
<ul class="wpcode-admin-tabs">
|
||||
<?php
|
||||
foreach ( $this->views as $slug => $label ) {
|
||||
$class = $this->view === $slug ? 'active' : '';
|
||||
?>
|
||||
<li>
|
||||
<a href="<?php echo esc_url( $this->get_view_link( $slug ) ); ?>" class="<?php echo esc_attr( $class ); ?>"><?php echo esc_html( $label ); ?></a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Form for Facebook Pixel.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_facebook() {
|
||||
?>
|
||||
<h2><?php esc_html_e( 'Facebook Pixel', 'insert-headers-and-footers' ); ?></h2>
|
||||
<?php
|
||||
$this->metabox_row(
|
||||
__( 'Facebook Pixel ID', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'facebook_pixel_id',
|
||||
$this->get_option( 'facebook_pixel_id', '' ),
|
||||
sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing anchor tags.
|
||||
__( 'You can find your Facebook Pixel ID in the Facebook Ads Manager. %1$sRead our step by step directions%2$s. ', 'insert-headers-and-footers' ),
|
||||
'<a target="_blank" href="' . wpcode_utm_url( 'https://wpcode.com/docs/how-to-find-your-facebook-pixel-id-and-conversions-api-token/', 'conversion-pixels', 'facebook', 'pixel' ) . '">',
|
||||
'</a>'
|
||||
)
|
||||
),
|
||||
'facebook_pixel_id'
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'Conversions API Token', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'facebook_pixel_api_token',
|
||||
$this->get_option( 'facebook_pixel_api_token', '' ),
|
||||
__( 'The Conversions API token allows you to send API events that are more reliable and can improve audience targeting.', 'insert-headers-and-footers' ),
|
||||
true
|
||||
),
|
||||
'facebook_pixel_api_token'
|
||||
);
|
||||
?>
|
||||
<button type="button" class="wpcode-button wpcode-button-secondary wpcode-add-pixel"><?php esc_html_e( 'Add Another Pixel', 'insert-headers-and-footers' ); ?></button>
|
||||
<?php
|
||||
$this->metabox_row(
|
||||
__( 'Facebook Pixel Events', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_inputs(
|
||||
array(
|
||||
array(
|
||||
'label' => __( 'PageView Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'page_view',
|
||||
'description' => __( 'Enable the PageView event to track and record page visits on all the pages of your website using the Facebook Pixel.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => false,
|
||||
),
|
||||
),
|
||||
'facebook_pixel_events'
|
||||
)
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'eCommerce Events Tracking', 'insert-headers-and-footers' ),
|
||||
$this->get_ecommerce_events_input() . $this->get_checkbox_inputs( $this->get_fb_pixel_events_inputs(), 'facebook_pixel_events' )
|
||||
);
|
||||
wp_nonce_field( 'wpcode-save-facebook-pixel-data', 'wpcode-pixel-nonce' );
|
||||
?>
|
||||
<button type="submit" class="wpcode-button">
|
||||
<?php esc_html_e( 'Save Changes', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Form for Google Pixel.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_google() {
|
||||
?>
|
||||
<h2><?php esc_html_e( 'Google Analytics & Ads Tracking', 'insert-headers-and-footers' ); ?></h2>
|
||||
<?php
|
||||
$this->metabox_row(
|
||||
__( 'Google Analytics ID', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'google_analytics_id',
|
||||
$this->get_option( 'google_analytics_id', '' ),
|
||||
sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing anchor tags.
|
||||
__( 'You can find your Google Analytics ID in the Google Analytics Admin panel. %1$sRead our step by step directions%2$s. ', 'insert-headers-and-footers' ),
|
||||
'<a target="_blank" href="' . wpcode_utm_url( 'https://wpcode.com/docs/how-to-find-your-google-analytics-id/', 'conversion-pixels', 'google', 'pixel' ) . '">',
|
||||
'</a>'
|
||||
)
|
||||
),
|
||||
'google_analytics_id'
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'Google Ads Tag ID', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'google_ads_id',
|
||||
$this->get_option( 'google_ads_id', '' ),
|
||||
sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing anchor tags.
|
||||
__( 'You can find your Google Ads Tag ID in the Google Ads Settings under Google Tag. %1$sRead our step by step directions%2$s. ', 'insert-headers-and-footers' ),
|
||||
'<a target="_blank" href="' . wpcode_utm_url( 'https://wpcode.com/docs/how-to-find-your-google-ads-tag-id/', 'conversion-pixels', 'google', 'pixel' ) . '">',
|
||||
'</a>'
|
||||
)
|
||||
),
|
||||
'google_ads_id'
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'Ads Conversion Label', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'google_ads_label',
|
||||
$this->get_option( 'google_ads_label', '' ),
|
||||
sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing anchor tags.
|
||||
__( 'Add your Google Ads Conversion Label for tracking conversion events. %1$sLearn More%2$s.', 'insert-headers-and-footers' ),
|
||||
'<a target="_blank" href="' . wpcode_utm_url( 'https://wpcode.com/docs/how-to-find-your-google-ads-tag-id/', 'conversion-pixels', 'google', 'pixel' ) . '">',
|
||||
'</a>'
|
||||
)
|
||||
),
|
||||
'google_ads_label'
|
||||
);
|
||||
?>
|
||||
<button type="button" class="wpcode-button wpcode-button-secondary wpcode-add-pixel"><?php esc_html_e( 'Add Google ID', 'insert-headers-and-footers' ); ?></button>
|
||||
<?php
|
||||
$this->metabox_row(
|
||||
__( 'Google Events', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_inputs(
|
||||
array(
|
||||
array(
|
||||
'label' => __( 'PageView Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'page_view',
|
||||
'description' => __( 'Enable PageView event on all pages.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => false,
|
||||
),
|
||||
),
|
||||
'google_pixel_events'
|
||||
)
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'eCommerce Events Tracking', 'insert-headers-and-footers' ),
|
||||
$this->get_ecommerce_events_input() . $this->get_checkbox_inputs( $this->get_google_pixel_events_inputs(), 'google_pixel_events' )
|
||||
);
|
||||
wp_nonce_field( 'wpcode-save-google-pixel-data', 'wpcode-pixel-nonce' );
|
||||
?>
|
||||
<button type="submit" class="wpcode-button">
|
||||
<?php esc_html_e( 'Save Changes', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings for the Pinterest pixel.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_pinterest() {
|
||||
?>
|
||||
<h2><?php esc_html_e( 'Pinterest Tag', 'insert-headers-and-footers' ); ?></h2>
|
||||
<?php
|
||||
$this->metabox_row(
|
||||
__( 'Tag ID', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'pinterest_id',
|
||||
$this->get_option( 'pinterest_id', '' ),
|
||||
sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing anchor tags.
|
||||
__( 'You can find your Tag id in your Pinterest Business account. %1$sRead our step by step directions%2$s. ', 'insert-headers-and-footers' ),
|
||||
'<a target="_blank" href="' . wpcode_utm_url( 'https://wpcode.com/docs/how-to-find-your-pinterest-tag-id-and-conversion-access-token/', 'conversion-pixels', 'pinterest', 'pixel' ) . '">',
|
||||
'</a>'
|
||||
)
|
||||
),
|
||||
'pinterest_id'
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'Ad Account ID', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'pinterest_ad_account_id',
|
||||
$this->get_option( 'pinterest_ad_account_id', '' ),
|
||||
sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing anchor tags.
|
||||
__( 'You can find your Ad Account ID in your Pinterest Business account. %1$sRead more%2$s. ', 'insert-headers-and-footers' ),
|
||||
'<a target="_blank" href="' . wpcode_utm_url( 'https://wpcode.com/docs/how-to-find-your-pinterest-tag-id-and-conversion-access-token/', 'conversion-pixels', 'pinterest', 'pixel' ) . '">',
|
||||
'</a>'
|
||||
)
|
||||
),
|
||||
'pinterest_ad_account_id'
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'Conversion Access Token', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'pinterest_conversion_token',
|
||||
$this->get_option( 'pinterest_conversion_token', '' ),
|
||||
sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing anchor tags.
|
||||
__( 'You can find your Conversion Access Token under Ads > Conversions > Conversion access token. %1$sRead more%2$s. ', 'insert-headers-and-footers' ),
|
||||
'<a target="_blank" href="' . wpcode_utm_url( 'https://wpcode.com/docs/how-to-find-your-pinterest-tag-id-and-conversion-access-token/', 'conversion-pixels', 'pinterest', 'pixel' ) . '">',
|
||||
'</a>'
|
||||
),
|
||||
true
|
||||
),
|
||||
'pinterest_conversion_token'
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'eCommerce Events Tracking', 'insert-headers-and-footers' ),
|
||||
$this->get_ecommerce_events_input() . $this->get_checkbox_inputs( $this->get_pinterest_pixel_events_inputs(), 'pinterest_pixel_events' )
|
||||
);
|
||||
wp_nonce_field( 'wpcode-save-pinterest-pixel-data', 'wpcode-pixel-nonce' );
|
||||
?>
|
||||
<button type="submit" class="wpcode-button">
|
||||
<?php esc_html_e( 'Save Changes', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings for the Pinterest pixel.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_tiktok() {
|
||||
?>
|
||||
<h2><?php esc_html_e( 'TikTok Pixel', 'insert-headers-and-footers' ); ?></h2>
|
||||
<?php
|
||||
$this->metabox_row(
|
||||
__( 'Pixel ID', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'tiktok_pixel_id',
|
||||
$this->get_option( 'tiktok_pixel_id', '' ),
|
||||
sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing anchor tags.
|
||||
__( 'You can find your Pixel id in your TikTok Business Account. %1$sRead our step by step directions%2$s.', 'insert-headers-and-footers' ),
|
||||
'<a target="_blank" href="' . wpcode_utm_url( 'https://wpcode.com/docs/how-to-find-your-tiktok-pixel-id-and-events-api-access-token/', 'conversion-pixels', 'tiktok', 'pixel' ) . '">',
|
||||
'</a>'
|
||||
)
|
||||
),
|
||||
'tiktok_pixel_id'
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'Events API Access Token', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'tiktok_access_token',
|
||||
$this->get_option( 'tiktok_access_token', '' ),
|
||||
sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing anchor tags.
|
||||
__( 'You can generate an access token in the Pixel Settings under Access Token Generation. %1$sRead more%2$s', 'insert-headers-and-footers' ),
|
||||
'<a target="_blank" href="' . wpcode_utm_url( 'https://wpcode.com/docs/how-to-find-your-tiktok-pixel-id-and-events-api-access-token/', 'conversion-pixels', 'tiktok', 'pixel' ) . '">',
|
||||
'</a>'
|
||||
),
|
||||
true
|
||||
),
|
||||
'tiktok_access_token'
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'eCommerce Events Tracking', 'insert-headers-and-footers' ),
|
||||
$this->get_ecommerce_events_input() . $this->get_checkbox_inputs( $this->get_tiktok_pixel_events_inputs(), 'tiktok_pixel_events' )
|
||||
);
|
||||
wp_nonce_field( 'wpcode-save-tiktok-pixel-data', 'wpcode-pixel-nonce' );
|
||||
?>
|
||||
<button type="submit" class="wpcode-button">
|
||||
<?php esc_html_e( 'Save Changes', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Page for Snapchat pixel settings.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_snapchat() {
|
||||
?>
|
||||
<h2><?php esc_html_e( 'Snapchat Pixel', 'insert-headers-and-footers' ); ?></h2>
|
||||
<?php
|
||||
$this->metabox_row(
|
||||
__( 'Snap Pixel ID', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'snapchat_pixel_id',
|
||||
$this->get_option( 'snapchat_pixel_id', '' ),
|
||||
sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing anchor tags.
|
||||
__( 'You can find your Snapchat Pixel ID in the Snapchat Ads Manager. %1$sRead our step by step directions%2$s. ', 'insert-headers-and-footers' ),
|
||||
'<a target="_blank" href="' . wpcode_utm_url( 'https://wpcode.com/docs/how-to-find-your-snapchat-pixel-id-and-conversions-api-token/', 'conversion-pixels', 'snapchat', 'pixel' ) . '">',
|
||||
'</a>'
|
||||
),
|
||||
true
|
||||
),
|
||||
'snapchat_pixel_id'
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'Conversions API Token', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'snapchat_pixel_api_token',
|
||||
$this->get_option( 'snapchat_pixel_api_token', '' ),
|
||||
__( 'The Conversions API token allows you to send API events that are more reliable and can improve audience targeting.', 'insert-headers-and-footers' ),
|
||||
true
|
||||
),
|
||||
'snapchat_pixel_api_token'
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'Snapchat Pixel Events', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_inputs(
|
||||
array(
|
||||
array(
|
||||
'label' => __( 'Pave View Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'page_view',
|
||||
'description' => __( 'Enable the PAGE_VIEW event to track and record page visits on all the pages of your website using the Snapchat Pixel.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => false,
|
||||
),
|
||||
),
|
||||
'snapchat_pixel_events'
|
||||
)
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'eCommerce Events Tracking', 'insert-headers-and-footers' ),
|
||||
$this->get_ecommerce_events_input() . $this->get_checkbox_inputs( $this->get_snap_pixel_events_inputs(), 'snapchat_pixel_events' )
|
||||
);
|
||||
wp_nonce_field( 'wpcode-save-snapchat-pixel-data', 'wpcode-pixel-nonce' );
|
||||
?>
|
||||
<button type="submit" class="wpcode-button">
|
||||
<?php esc_html_e( 'Save Changes', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Page for OpenAI pixel settings.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_openai() {
|
||||
?>
|
||||
<h2><?php esc_html_e( 'OpenAI Ads Measurement Pixel', 'insert-headers-and-footers' ); ?></h2>
|
||||
<?php
|
||||
$this->metabox_row(
|
||||
__( 'OpenAI Pixel ID', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'openai_pixel_id',
|
||||
$this->get_option( 'openai_pixel_id', '' ),
|
||||
__( 'Enter the Pixel ID from OpenAI Ads Manager to load the OpenAI Ads Measurement Pixel on your site.', 'insert-headers-and-footers' ),
|
||||
true
|
||||
),
|
||||
'openai_pixel_id'
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'OpenAI Conversion Key', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'openai_pixel_api_key',
|
||||
$this->get_option( 'openai_pixel_api_key', '' ),
|
||||
__( 'Enter the Conversion Key from your OpenAI Ads Manager > Conversions tab to send matching server-side events. This is not your platform API key.', 'insert-headers-and-footers' ),
|
||||
true
|
||||
),
|
||||
'openai_pixel_api_key'
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'OpenAI Pixel Events', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_inputs(
|
||||
array(
|
||||
array(
|
||||
'label' => __( 'Page Viewed Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'page_view',
|
||||
'description' => __( 'Enable the "page_viewed" event to track and record page visits on all pages using the OpenAI Ads Measurement Pixel.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => false,
|
||||
),
|
||||
),
|
||||
'openai_pixel_events'
|
||||
)
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'eCommerce Events Tracking', 'insert-headers-and-footers' ),
|
||||
$this->get_ecommerce_events_input() . $this->get_checkbox_inputs( $this->get_openai_pixel_events_inputs(), 'openai_pixel_events' )
|
||||
);
|
||||
wp_nonce_field( 'wpcode-save-openai-pixel-data', 'wpcode-pixel-nonce' );
|
||||
?>
|
||||
<button type="submit" class="wpcode-button">
|
||||
<?php esc_html_e( 'Save Changes', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Event options checkboxes for Facebook Pixel.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function get_fb_pixel_events_inputs() {
|
||||
return array(
|
||||
array(
|
||||
'label' => __( 'ViewContent Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'view_content',
|
||||
'description' => __( 'Turn on the "ViewContent" event to track views of product pages on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'view-content',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'AddtoCart Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'add_to_cart',
|
||||
'description' => __( 'Turn on the "AddToCart" event to track when items are added to a shopping cart on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'add-to-cart',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'InitiateCheckout Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'begin_checkout',
|
||||
'description' => __( 'Turn on the "InitiateCheckout" event to track when a user reaches the checkout page on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'begin-checkout',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Purchase Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'purchase',
|
||||
'description' => __( 'Turn on the "Purchase" event to track successful purchases on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'purchase',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Events checkboxes for Google Analytics & Ads.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function get_google_pixel_events_inputs() {
|
||||
return array(
|
||||
array(
|
||||
'label' => __( 'View Item Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'view_item',
|
||||
'description' => __( 'Send the View Item event to track views of product pages on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'view-content',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Add to Cart Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'add_to_cart',
|
||||
'description' => __( 'Send the Add to Cart event when a product is added to the cart.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'add-to-cart',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Begin Checkout Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'begin_checkout',
|
||||
'description' => __( 'Send the Begin Checkout event when the user sees the checkout page.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'begin-checkout',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Purchase Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'purchase',
|
||||
'description' => __( 'Send the Purchase event when the user completes a purchase.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'purchase',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Conversion Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'conversion',
|
||||
'description' => __( 'Send the conversion event with the Google Ads label set above on a successful purchase.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'conversion',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Events checkboxes for Pinterest.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function get_pinterest_pixel_events_inputs() {
|
||||
return array(
|
||||
array(
|
||||
'label' => __( 'PageVisit Product Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'pagevisit_product',
|
||||
'description' => __( 'Turn on the "PageVisit" event to track views of product pages on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'view-content ',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Add to Cart Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'add_to_cart',
|
||||
'description' => __( 'Turn on the Add to Cart event to track when items are added to a shopping cart on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'add-to-cart',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Checkout PageVisit Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'begin_checkout',
|
||||
'description' => __( 'Enable the Checkout PageVisit event to track when a user reaches the checkout page on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'begin-checkout',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Checkout Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'purchase',
|
||||
'description' => __( 'Turn on the "Checkout" event to track successful purchases on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'purchase',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Events checkboxes for TikTok.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function get_tiktok_pixel_events_inputs() {
|
||||
return array(
|
||||
array(
|
||||
'label' => __( 'ViewContent Product Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'view_content',
|
||||
'description' => __( 'Turn on the "ViewContent" event to track views of product pages on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'view-content',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Add to Cart Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'add_to_cart',
|
||||
'description' => __( 'Turn on the "AddToCart" event to track when items are added to a shopping cart on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'add-to-cart',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'InitiateCheckout Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'begin_checkout',
|
||||
'description' => __( 'Turn on the "InitiateCheckout" event to track when a user reaches the checkout page on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'begin-checkout',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'PlaceAnOrder Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'purchase',
|
||||
'description' => __( 'Turn on the "PlaceAnOrder" event to track successful purchases on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'purchase',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the markup for a list of checkboxes.
|
||||
*
|
||||
* @param array $inputs The details for the checkbox inputs.
|
||||
* @param string $name The name of the inputs.
|
||||
* @param string $pixel_options_key The key of the pixel options (defaults to $name above if not set).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_checkbox_inputs( $inputs, $name, $pixel_options_key = '' ) {
|
||||
$markup = '';
|
||||
if ( empty( $pixel_options_key ) ) {
|
||||
$pixel_options_key = $name;
|
||||
}
|
||||
$pixel_options = $this->get_option( $pixel_options_key, array() );
|
||||
$ecommerce_vendors = $this->ecommerce_available();
|
||||
|
||||
foreach ( $inputs as $input ) {
|
||||
$row_class = isset( $input['css_class'] ) ? $input['css_class'] : '';
|
||||
$input_name = $name . '[' . $input['name'] . ']';
|
||||
$checked = ! empty( $pixel_options[ $input['name'] ] );
|
||||
if ( $input['ecommerce'] && empty( $ecommerce_vendors ) ) {
|
||||
$row_class = ' wpcode-checkbox-row-disabled';
|
||||
}
|
||||
$markup .= '<div class="wpcode-checkbox-row ' . $row_class . '">';
|
||||
$markup .= $this->get_checkbox_toggle(
|
||||
$checked,
|
||||
$input_name,
|
||||
$input['description'],
|
||||
1,
|
||||
$input['label']
|
||||
);
|
||||
$markup .= '</div>';
|
||||
}
|
||||
|
||||
return $markup;
|
||||
}
|
||||
|
||||
/**
|
||||
* There's no actual value to show in this instance.
|
||||
*
|
||||
* @param string $key The key of the option.
|
||||
* @param mixed $default The default value of the option.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_option( $key, $default = false ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we have a supported eCommerce plugin installed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function ecommerce_available() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the markup for the eCommerce events input.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_ecommerce_events_input() {
|
||||
$providers = $this->ecommerce_available();
|
||||
|
||||
$markup = '<div class="wpcode-label-text-row">';
|
||||
if ( empty( $providers ) ) {
|
||||
$markup .= '<p><strong>' . __( 'Disabled, no eCommerce Platform Detected', 'insert-headers-and-footers' ) . '</strong></p>';
|
||||
} else {
|
||||
foreach ( $providers as $provider ) {
|
||||
// translators: %s is the name of the eCommerce provider.
|
||||
$markup .= '<p><strong>' . sprintf( __( '%s Tracking Enabled', 'insert-headers-and-footers' ), $provider ) . '</strong></p>';
|
||||
}
|
||||
}
|
||||
$markup .= '<p>';
|
||||
$markup .= sprintf(
|
||||
// translators: %s a html break.
|
||||
__( 'Advanced eCommerce tracking is available for WooCommerce, Easy Digital Downloads and MemberPress. %s These plugins are detected automatically and when available you can toggle individual events using the options below.', 'insert-headers-and-footers' ),
|
||||
'</br>'
|
||||
);
|
||||
$markup .= '</p>';
|
||||
$markup .= '</div>';
|
||||
|
||||
return $markup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event options checkboxes for the Snapchat Pixel.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function get_snap_pixel_events_inputs() {
|
||||
return array(
|
||||
array(
|
||||
'label' => __( 'View Content Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'view_content',
|
||||
'description' => __( 'Turn on the "VIEW_CONTENT" event to track views of product pages on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'view-content',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Add to Cart Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'add_to_cart',
|
||||
'description' => __( 'Turn on the "ADD_CART" event to track when items are added to a shopping cart on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'add-to-cart',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Start Checkout Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'begin_checkout',
|
||||
'description' => __( 'Turn on the "START_CHECKOUT" event to track when a user reaches the checkout page on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'begin-checkout',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Purchase Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'purchase',
|
||||
'description' => __( 'Turn on the "PURCHASE" event to track successful purchases on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'purchase',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event options checkboxes for the OpenAI Ads Measurement Pixel.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function get_openai_pixel_events_inputs() {
|
||||
return array(
|
||||
array(
|
||||
'label' => __( 'Contents Viewed Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'view_content',
|
||||
'description' => __( 'Turn on the "contents_viewed" event to track views of product pages on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'view-content',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Items Added Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'add_to_cart',
|
||||
'description' => __( 'Turn on the "items_added" event to track when items are added to a shopping cart on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'add-to-cart',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Checkout Started Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'begin_checkout',
|
||||
'description' => __( 'Turn on the "checkout_started" event to track when a user reaches the checkout page on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'begin-checkout',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Order Created Event', 'insert-headers-and-footers' ),
|
||||
'name' => 'purchase',
|
||||
'description' => __( 'Turn on the "order_created" event to track successful purchases on your website.', 'insert-headers-and-footers' ),
|
||||
'ecommerce' => true,
|
||||
'css_class' => 'purchase',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the page content for the Custom Events page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_click_tracking() {
|
||||
?>
|
||||
<h2><?php esc_html_e( 'Custom Click Tracking', 'insert-headers-and-footers' ); ?></h2>
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
/* Translators: %1$s is the opening link tag, %2$s is the closing link tag */
|
||||
esc_html__( 'Use this section to add custom click events to your site. You can add as many as you like. Each event can have multiple pixels and each pixel can have a custom event name and value. Read more about how to configure these settings in %1$sthis article%2$s', 'insert-headers-and-footers' ),
|
||||
'<a href="' . esc_url( wpcode_utm_url( 'https://wpcode.com/docs/conversion-pixels-custom-click-tracking/' ) ) . '" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<div id="wpcode-settings-repeater" class="wpcode-settings-repeater-group">
|
||||
<div class="wpcode-settings-repeater-item">
|
||||
<?php
|
||||
$this->metabox_row(
|
||||
__( 'CSS Selector', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'',
|
||||
'',
|
||||
sprintf(
|
||||
// Translators: %1$s is an opening anchor tag, %2$s is a closing anchor tag.
|
||||
esc_html__( 'Define the HTML element that triggers the event upon clicking (button, link, etc). Input the appropriate CSS selector here. %1$sLearn more%2$s', 'insert-headers-and-footers' ),
|
||||
'<a href="' . esc_url( wpcode_utm_url( 'https://wpcode.com/docs/finding-css-selector/' ) ) . '" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
true
|
||||
)
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'Event Name', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'',
|
||||
'',
|
||||
__( 'Assign a unique identifier to your event for easy recognition and categorization. ', 'insert-headers-and-footers' )
|
||||
)
|
||||
);
|
||||
$this->metabox_row(
|
||||
__( 'Event Value', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'',
|
||||
'',
|
||||
__( 'Input a numerical value for your event. This helps in quantifying user interactions for your tracking needs. ', 'insert-headers-and-footers' )
|
||||
)
|
||||
);
|
||||
?>
|
||||
<div class="wpcode-pixels-chooser-row">
|
||||
<div class="wpcode-metabox-form-row">
|
||||
<div class="wpcode-metabox-form-row-label">
|
||||
<label for="">Pixels </label>
|
||||
</div>
|
||||
<div class="wpcode-metabox-form-row-input">
|
||||
<p>Choose which pixels to enable for this event. </p>
|
||||
<p>You can choose a standard event for each pixel to override the custom event label set
|
||||
above.</p>
|
||||
<?php
|
||||
$pixels = array(
|
||||
'Facebook',
|
||||
'Google',
|
||||
'Pinterest',
|
||||
'TikTok',
|
||||
'Snapchat',
|
||||
__( 'OpenAI', 'insert-headers-and-footers' ),
|
||||
);
|
||||
foreach ( $pixels as $pixel ) {
|
||||
echo '<div class="wpcode-checkbox-row">';
|
||||
echo $this->get_checkbox_toggle( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
true,
|
||||
'',
|
||||
'',
|
||||
1,
|
||||
$pixel // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="wpcode-button wpcode-button-secondary" id="wpcode-add-click-event">
|
||||
<?php esc_html_e( 'Add New Click Event', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<?php
|
||||
wp_nonce_field( 'wpcode-save-click-pixel-data', 'insert-headers-and-footers-nonce' );
|
||||
?>
|
||||
<button type="submit" class="wpcode-button">
|
||||
<?php esc_html_e( 'Save Changes', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin page for the Search & Replace tool.
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for the Search & Replace admin page.
|
||||
*/
|
||||
class WPCode_Admin_Page_Search_Replace extends WPCode_Admin_Page {
|
||||
|
||||
/**
|
||||
* The page slug to be used when adding the submenu.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $page_slug = 'wpcode-search-replace';
|
||||
|
||||
/**
|
||||
* The action used for the nonce.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $action = 'wpcode-search-replace';
|
||||
|
||||
/**
|
||||
* The nonce name field.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $nonce_name = 'wpcode-search-replace_nonce';
|
||||
|
||||
/**
|
||||
* Call this just to set the page title translatable.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->page_title = 'Search & Replace Everything';
|
||||
$this->menu_title = 'Search & Replace';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hook on admin init just for this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_hooks() {
|
||||
add_action( 'admin_init', array( $this, 'maybe_redirect_to_search_replace' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to hide default header on this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the search replace page if the plugin is active.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_redirect_to_search_replace() {
|
||||
if ( function_exists( 'wsrw_main' ) ) {
|
||||
wp_safe_redirect( admin_url( 'tools.php?page=wsrw-search-replace' ) );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The page output.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_content() {
|
||||
?>
|
||||
<div class="wpcode-plugin-page wpcode-plugin-page-search-replace">
|
||||
<div class="wpcode-plugin-page-image">
|
||||
<?php wpcode_icon( 'logo-sr', 90, 90, '0 0 65 64' ); ?>
|
||||
</div>
|
||||
<div class="wpcode-plugin-page-title">
|
||||
<h1>Search & Replace Everything by WPCode</h1>
|
||||
<p>
|
||||
<?php esc_html_e( 'Confidently replace any text in your database and update images without duplicating uploads, all with a single plugin.', 'insert-headers-and-footers' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
<section class="wpcode-plugin-screenshot">
|
||||
<div class="wpcode-plugin-screenshot-image">
|
||||
<img src="<?php echo esc_url( WPCODE_PLUGIN_URL ); // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage?>admin/images/sr-screenshot-thumb.jpg" alt="<?php esc_attr_e( 'Search & Replace Everything Screenshot', 'insert-headers-and-footers' ); ?>"/>
|
||||
<a href="<?php echo esc_url( WPCODE_PLUGIN_URL ); ?>admin/images/sr-screenshot.jpg" data-lity>
|
||||
<?php wpcode_icon( 'search', 16, 16 ); ?>
|
||||
</a>
|
||||
</div>
|
||||
<ul>
|
||||
<li><?php esc_html_e( 'Replace Text Across Your Whole Database.', 'insert-headers-and-footers' ); ?></li>
|
||||
<li><?php esc_html_e( 'Preview Changes Every Time.', 'insert-headers-and-footers' ); ?></li>
|
||||
<li><?php esc_html_e( 'Replace Image Sources to Clear Up Space.', 'insert-headers-and-footers' ); ?></li>
|
||||
<li><?php esc_html_e( 'Support for Serialized Data.', 'insert-headers-and-footers' ); ?></li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="wpcode-plugin-step wpcode-plugin-step-install">
|
||||
<aside class="wpcode-plugin-page-step-num">
|
||||
<?php wpcode_icon( 'step-1', 50, 50, '0 0 100 100' ); ?>
|
||||
<i class="wpcode-plugin-page-step-loader wpcode-plugin-page-step-loader-hidden"></i>
|
||||
</aside>
|
||||
<div>
|
||||
<h2>
|
||||
<?php
|
||||
printf(
|
||||
// translators: %s is the plugin name.
|
||||
esc_html__( 'Install and Activate %s', 'insert-headers-and-footers' ),
|
||||
'Search & Replace Everything'
|
||||
)
|
||||
?>
|
||||
</h2>
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
// translators: %s is the plugin name.
|
||||
esc_html__( 'Install %s from the WordPress.org plugin repository.', 'insert-headers-and-footers' ),
|
||||
'Search & Replace Everything'
|
||||
)
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
// Let's check if you can install plugins on this site.
|
||||
if ( current_user_can( 'install_plugins' ) && wp_is_file_mod_allowed( 'install_plugins' ) ) {
|
||||
?>
|
||||
<button class="wpcode-button wpcode-button-install-plugin" data-slug="search-replace-wpcode">
|
||||
<?php
|
||||
printf(
|
||||
// translators: %s is the plugin name.
|
||||
esc_html__( 'Install %s', 'insert-headers-and-footers' ),
|
||||
'Search & Replace Everything'
|
||||
);
|
||||
?>
|
||||
</button>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<p>
|
||||
<?php esc_html_e( 'Please ask your website administrator to install Search & Replace Everything.', 'insert-headers-and-footers' ); ?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* For this page we output a title and the save button.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header_bottom() {
|
||||
}
|
||||
}
|
||||
+825
@@ -0,0 +1,825 @@
|
||||
<?php
|
||||
/**
|
||||
* Settings admin page.
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for the Settings admin page.
|
||||
*/
|
||||
class WPCode_Admin_Page_Settings extends WPCode_Admin_Page {
|
||||
|
||||
/**
|
||||
* The page slug to be used when adding the submenu.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $page_slug = 'wpcode-settings';
|
||||
|
||||
/**
|
||||
* The action used for the nonce.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $action = 'wpcode-settings';
|
||||
|
||||
/**
|
||||
* The nonce name field.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $nonce_name = 'wpcode-settings_nonce';
|
||||
|
||||
/**
|
||||
* The view to be loaded by default.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $view = 'general';
|
||||
|
||||
/**
|
||||
* The capability required to view this page.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $capability = 'wpcode_manage_settings';
|
||||
|
||||
/**
|
||||
* Call this just to set the page title translatable.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->page_title = __( 'WPCode Settings', 'insert-headers-and-footers' );
|
||||
$this->menu_title = __( 'Settings', 'insert-headers-and-footers' );
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup page-specific views.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setup_views() {
|
||||
$this->views = array(
|
||||
'general' => __( 'General Settings', 'insert-headers-and-footers' ),
|
||||
'errors' => __( 'Error Handling', 'insert-headers-and-footers' ),
|
||||
'access' => __( 'Access Control', 'insert-headers-and-footers' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hook on admin init just for this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_hooks() {
|
||||
$this->process_message();
|
||||
add_action( 'admin_init', array( $this, 'submit_listener' ) );
|
||||
add_filter( 'wpcode_admin_js_data', array( $this, 'add_connect_strings' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the message after the settings are saved with a redirect.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process_message() {
|
||||
if ( isset( $_GET['message'] ) && 1 === absint( $_GET['message'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$this->set_success_message( __( 'Settings Saved.', 'insert-headers-and-footers' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap this page in a form tag.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output() {
|
||||
?>
|
||||
<form action="<?php echo esc_url( $this->get_page_action_url() ); ?>" method="post">
|
||||
<?php parent::output(); ?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* The Settings page output.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_content() {
|
||||
if ( method_exists( $this, 'output_view_' . $this->view ) ) {
|
||||
call_user_func( array( $this, 'output_view_' . $this->view ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Settings page output.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_general() {
|
||||
$header_and_footers = wpcode()->settings->get_option( 'headers_footers_mode' );
|
||||
$usage_tracking = wpcode()->settings->get_option( 'usage_tracking' );
|
||||
|
||||
$description = __( 'This allows you to disable all Code Snippets functionality and have a single "Headers & Footers" item under the settings menu.', 'insert-headers-and-footers' );
|
||||
|
||||
$description .= '<br />';
|
||||
$description .= sprintf(
|
||||
// Translators: Placeholders make the text bold.
|
||||
__( '%1$sNOTE:%2$s Please use this setting with caution. It will disable all custom snippets that you add using the new snippet management interface.', 'insert-headers-and-footers' ),
|
||||
'<strong>',
|
||||
'</strong>'
|
||||
);
|
||||
|
||||
$this->metabox_row(
|
||||
__( 'License Key', 'insert-headers-and-footers' ),
|
||||
$this->get_license_key_input()
|
||||
);
|
||||
|
||||
$this->metabox_row(
|
||||
__( 'Headers & Footers mode', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_toggle(
|
||||
$header_and_footers,
|
||||
'headers_footers_mode',
|
||||
$description
|
||||
),
|
||||
'headers_footers_mode'
|
||||
);
|
||||
|
||||
$this->common_settings();
|
||||
|
||||
$this->php_load_as_file_setting_upsell();
|
||||
|
||||
$this->metabox_row(
|
||||
__( 'Allow Usage Tracking', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_toggle(
|
||||
$usage_tracking,
|
||||
'usage_tracking',
|
||||
esc_html__( 'By allowing us to track usage data, we can better help you, as we will know which WordPress configurations, themes, and plugins we should test.', 'insert-headers-and-footers' )
|
||||
),
|
||||
'usage_tracking'
|
||||
);
|
||||
|
||||
$this->uninstall_setting();
|
||||
|
||||
wp_nonce_field( $this->action, $this->nonce_name );
|
||||
|
||||
?>
|
||||
<button class="wpcode-button" type="submit">
|
||||
<?php esc_html_e( 'Save Changes', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the uninstall setting.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall_setting() {
|
||||
$uninstall_description = esc_html__( 'Remove ALL WPCode data upon plugin deletion.', 'insert-headers-and-footers' );
|
||||
|
||||
$uninstall_description .= '<br />';
|
||||
$uninstall_description .= sprintf(
|
||||
'<strong style="color: #DF2A35">%s</strong>',
|
||||
esc_html__( 'All WPCode snippets & scripts will be unrecoverable.', 'insert-headers-and-footers' )
|
||||
);
|
||||
|
||||
$this->metabox_row(
|
||||
__( 'Delete All Data on Uninstall', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_toggle(
|
||||
wpcode()->settings->get_option( 'uninstall_data', false ),
|
||||
'wpcode-uninstall-data',
|
||||
$uninstall_description,
|
||||
1
|
||||
),
|
||||
'wpcode-admin-bar-info'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move common settings to a separate method so we can use it in other versions of this page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function common_settings() {
|
||||
$this->metabox_row(
|
||||
__( 'WPCode Library Connection', 'insert-headers-and-footers' ),
|
||||
$this->get_library_connection_input()
|
||||
);
|
||||
|
||||
$this->metabox_row(
|
||||
__( 'Editor Height', 'insert-headers-and-footers' ),
|
||||
$this->get_editor_height_input(),
|
||||
'wpcode-editor-height'
|
||||
);
|
||||
|
||||
$this->metabox_row(
|
||||
__( 'Dark Mode', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_toggle(
|
||||
wpcode()->settings->get_option( 'dark_mode' ),
|
||||
'wpcode-dark-mode',
|
||||
esc_html__( 'Enable Dark Mode across WPCode.', 'insert-headers-and-footers' ),
|
||||
1
|
||||
),
|
||||
'wpcode-dark-mode'
|
||||
);
|
||||
|
||||
$this->metabox_row(
|
||||
__( 'Admin Bar Info', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_toggle(
|
||||
wpcode()->settings->get_option( 'admin_bar_info', true ),
|
||||
'wpcode-admin-bar-info',
|
||||
esc_html__( 'Enable the admin bar menu that shows info about which snippets & scripts are loaded on the current page.', 'insert-headers-and-footers' ),
|
||||
1
|
||||
),
|
||||
'wpcode-admin-bar-info'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the PHP load as file setting upsell for lite users.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function php_load_as_file_setting_upsell() {
|
||||
$description = esc_html__( 'When enabled, all active PHP, HTML, and Universal snippets will be loaded from files instead of the database. Files are stored in ', 'insert-headers-and-footers' );
|
||||
|
||||
// Show site-specific path in multisite.
|
||||
if ( function_exists( 'is_multisite' ) && is_multisite() && function_exists( 'get_current_blog_id' ) ) {
|
||||
$blog_id = get_current_blog_id();
|
||||
if ( $blog_id > 0 ) {
|
||||
$file_path = str_replace( ABSPATH, '', WP_CONTENT_DIR . '/wpcode/snippets/site-' . absint( $blog_id ) . '/' );
|
||||
} else {
|
||||
$file_path = str_replace( ABSPATH, '', WP_CONTENT_DIR . '/wpcode/snippets/' );
|
||||
}
|
||||
} else {
|
||||
$file_path = str_replace( ABSPATH, '', WP_CONTENT_DIR . '/wpcode/snippets/' );
|
||||
}
|
||||
|
||||
$description .= '<code>' . esc_html( $file_path ) . '</code>';
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$description .= ' <strong>' . esc_html__( 'Note: In multisite networks, each site has its own file directory to prevent cross-site conflicts.', 'insert-headers-and-footers' ) . '</strong>';
|
||||
}
|
||||
|
||||
$this->metabox_row(
|
||||
__( 'Load PHP Snippets as Files', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_toggle(
|
||||
false,
|
||||
'wpcode-php-load-as-file',
|
||||
$description
|
||||
),
|
||||
'wpcode-php-load-as-file',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an input to connect or disconnect from the snippet library.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_library_connection_input() {
|
||||
$button_classes = array(
|
||||
'wpcode-button',
|
||||
);
|
||||
$button_text = __( 'Connect to the WPCode Library', 'insert-headers-and-footers' );
|
||||
if ( WPCode()->library_auth->has_auth() ) {
|
||||
$button_classes[] = 'wpcode-delete-auth';
|
||||
$button_text = __( 'Disconnect from the WPCode Library', 'insert-headers-and-footers' );
|
||||
} else {
|
||||
$button_classes[] = 'wpcode-start-auth';
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'<button type="button" class="%1$s">%2$s</button>',
|
||||
esc_attr( implode( ' ', $button_classes ) ),
|
||||
esc_html( $button_text )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* For this page we output a menu.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_header_bottom() {
|
||||
?>
|
||||
<div class="wpcode-column">
|
||||
<ul class="wpcode-admin-tabs">
|
||||
<?php
|
||||
foreach ( $this->views as $slug => $label ) {
|
||||
if ( 'importer' === $slug ) {
|
||||
continue;
|
||||
}
|
||||
$class = $this->view === $slug ? 'active' : '';
|
||||
?>
|
||||
<li>
|
||||
<a href="<?php echo esc_url( $this->get_view_link( $slug ) ); ?>" class="<?php echo esc_attr( $class ); ?>"><?php echo esc_html( $label ); ?></a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="wpcode-column">
|
||||
</div>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If the form is submitted attempt to save the values.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function submit_listener() {
|
||||
if ( ! isset( $_REQUEST[ $this->nonce_name ] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST[ $this->nonce_name ] ), $this->action ) ) {
|
||||
// Nonce is missing, so we're not even going to try.
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'errors' === $this->view ) {
|
||||
$settings = array(
|
||||
'error_logging' => isset( $_POST['wpcode-error-logging'] ),
|
||||
);
|
||||
} else {
|
||||
$settings = array(
|
||||
'headers_footers_mode' => isset( $_POST['headers_footers_mode'] ),
|
||||
'editor_height_auto' => isset( $_POST['editor_height_auto'] ),
|
||||
'editor_height' => isset( $_POST['editor_height'] ) ? absint( $_POST['editor_height'] ) : 300,
|
||||
'usage_tracking' => isset( $_POST['usage_tracking'] ),
|
||||
'admin_bar_info' => isset( $_POST['wpcode-admin-bar-info'] ),
|
||||
'dark_mode' => isset( $_POST['wpcode-dark-mode'] ),
|
||||
'uninstall_data' => isset( $_POST['wpcode-uninstall-data'] ),
|
||||
);
|
||||
}
|
||||
|
||||
$settings = $this->before_save( $settings );
|
||||
|
||||
wpcode()->settings->bulk_update_options( $settings );
|
||||
|
||||
if ( isset( $settings['headers_footers_mode'] ) && true === $settings['headers_footers_mode'] ) {
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
array(
|
||||
'page' => 'wpcode-headers-footers',
|
||||
'message' => 1,
|
||||
),
|
||||
admin_url( 'options-general.php' )
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
array(
|
||||
'message' => 1,
|
||||
),
|
||||
$this->get_page_action_url()
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give child classes a chance to update the settings object before saving.
|
||||
*
|
||||
* @param array $settings The settings to be saved.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function before_save( $settings ) {
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow users to change the code editor height.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_editor_height_input() {
|
||||
$editor_auto_height = boolval( wpcode()->settings->get_option( 'editor_height_auto' ) );
|
||||
$editor_height = wpcode()->settings->get_option( 'editor_height', 300 );
|
||||
|
||||
$html = sprintf(
|
||||
'<input type="number" min="100" value="%1$d" id="wpcode-editor-height" name="editor_height" %2$s />',
|
||||
absint( $editor_height ),
|
||||
disabled( $editor_auto_height, true, false )
|
||||
);
|
||||
|
||||
$html .= $this->get_checkbox_toggle(
|
||||
$editor_auto_height,
|
||||
'editor_height_auto'
|
||||
);
|
||||
$html .= '<label for="editor_height_auto">' . __( 'Auto height', 'insert-headers-and-footers' ) . '</label>';
|
||||
|
||||
$html .= '<p class="description">';
|
||||
$html .= esc_html__( 'Set the editor height in pixels or enable auto-grow so the code editor automatically grows in height with the code.', 'insert-headers-and-footers' );
|
||||
$html .= '</p>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the license key input.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_license_key_input() {
|
||||
ob_start();
|
||||
?>
|
||||
<div class="wpcode-metabox-form">
|
||||
<p><?php esc_html_e( 'You\'re using WPCode Lite - no license needed. Enjoy!', 'insert-headers-and-footers' ); ?> 🙂</p>
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
// Translators: %1$s - Opening anchor tag, do not translate. %2$s - Closing anchor tag, do not translate.
|
||||
esc_html__( 'To unlock more features consider %1$supgrading to PRO%2$s.', 'insert-headers-and-footers' ),
|
||||
'<strong><a href="' . esc_url( wpcode_utm_url( 'https://wpcode.com/lite/', 'settings-license', 'upgrading-to-pro' ) ) . '" target="_blank" rel="noopener noreferrer">',
|
||||
'</a></strong>'
|
||||
)
|
||||
?>
|
||||
</p>
|
||||
<hr>
|
||||
<p><?php esc_html_e( 'Already purchased? Simply enter your license key below to enable WPCode PRO!', 'insert-headers-and-footers' ); ?></p>
|
||||
<p>
|
||||
<input type="password" class="wpcode-input-text" id="wpcode-settings-upgrade-license-key" placeholder="<?php esc_attr_e( 'Paste license key here', 'insert-headers-and-footers' ); ?>" value="">
|
||||
<button type="button" class="wpcode-button" id="wpcode-settings-connect-btn">
|
||||
<?php esc_html_e( 'Verify Key', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the strings for the connect page to the JS object.
|
||||
*
|
||||
* @param array $data The localized data we already have.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_connect_strings( $data ) {
|
||||
$data['oops'] = esc_html__( 'Oops!', 'insert-headers-and-footers' );
|
||||
$data['ok'] = esc_html__( 'OK', 'insert-headers-and-footers' );
|
||||
$data['almost_done'] = esc_html__( 'Almost Done', 'insert-headers-and-footers' );
|
||||
$data['plugin_activate_btn'] = esc_html__( 'Activate', 'insert-headers-and-footers' );
|
||||
$data['server_error'] = esc_html__( 'Unfortunately there was a server connection error.', 'insert-headers-and-footers' );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the form for the access management tab.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_access() {
|
||||
echo '<div class="wpcode-blur-area">';
|
||||
$this->access_view_content();
|
||||
echo '</div>';
|
||||
echo $this->get_access_overlay(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the form for the access management tab.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function output_view_errors() {
|
||||
|
||||
$this->error_view_fields();
|
||||
|
||||
wp_nonce_field( $this->action, $this->nonce_name );
|
||||
|
||||
?>
|
||||
<button class="wpcode-button" type="submit">
|
||||
<?php esc_html_e( 'Save Changes', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The error handling tab fields.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function error_view_fields() {
|
||||
$this->error_logging_field();
|
||||
|
||||
?>
|
||||
<h2><?php esc_html_e( 'Email Notifications', 'insert-headers-and-footers' ); ?>
|
||||
<span class="wpcode-pro-pill">PRO</span></h2>
|
||||
<p>
|
||||
<?php esc_html_e( 'Receive email notifications when snippets throw errors or are automatically deactivated.', 'insert-headers-and-footers' ); ?>
|
||||
</p>
|
||||
<?php $this->wp_mail_smtp_notice(); ?>
|
||||
<hr/>
|
||||
<div style="position: relative">
|
||||
<div class="wpcode-blur-area">
|
||||
<?php
|
||||
$this->error_emails_fields();
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
echo self::get_upsell_box( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
esc_html__( 'Email Notifications is a Pro Feature', 'insert-headers-and-footers' ),
|
||||
'<p>' . esc_html__( 'Do you want to get email notifications the moment your snippets throw an error or are automatically deactivated? Upgrade today and improve your workflow with WPCode Error Email Notifications.', 'insert-headers-and-footers' ) . '</p>',
|
||||
array(
|
||||
'text' => esc_html__( 'Upgrade to WPCode PRO', 'insert-headers-and-footers' ),
|
||||
'url' => esc_url( wpcode_utm_url( 'https://wpcode.com/lite/', 'settings', 'tab-' . $this->view, 'email' ) ),
|
||||
)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* The fields used for email settings.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function error_emails_fields() {
|
||||
$this->metabox_row(
|
||||
__( 'Error Notifications', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_toggle(
|
||||
wpcode()->settings->get_option( 'emails_errors' ),
|
||||
'wpcode-emails-errors',
|
||||
sprintf(
|
||||
// Translators: %1$s: opening anchor tag, %2$s: closing anchor tag. Link to docs about error notifications.
|
||||
esc_html__( 'Send email notifications when snippets throw errors? %1$sLearn more%2$s', 'insert-headers-and-footers' ),
|
||||
'<a href="' . esc_url( wpcode_utm_url( 'https://wpcode.com/docs/error-notifications/', 'settings', 'errors', 'errornotifications' ) ) . '" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
1
|
||||
),
|
||||
'wpcode-error-notifications'
|
||||
);
|
||||
|
||||
$this->metabox_row(
|
||||
__( 'Send To', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'wpcode-emails-errors-addresses',
|
||||
wpcode()->settings->get_option( 'emails_errors_addresses', get_option( 'admin_email' ) ),
|
||||
__( 'Enter a comma separated list of email addresses to receive error notifications. Defaults to the admin email address.', 'insert-headers-and-footers' ),
|
||||
true
|
||||
),
|
||||
'wpcode-emails-errors-addresses'
|
||||
);
|
||||
|
||||
$preview_url = add_query_arg(
|
||||
array(
|
||||
'wpcode_email_template' => 'error',
|
||||
'wpcode_email_preview' => '1',
|
||||
),
|
||||
admin_url()
|
||||
);
|
||||
|
||||
$this->metabox_row(
|
||||
'',
|
||||
'<a href="' . esc_url( $preview_url ) . '" class="wpcode-button wpcode-button-secondary" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Preview Email', 'insert-headers-and-footers' ) . '</a>',
|
||||
'wpcode-emails-errors-preview'
|
||||
);
|
||||
|
||||
$this->metabox_row(
|
||||
__( 'Deactivation Notifications', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_toggle(
|
||||
wpcode()->settings->get_option( 'emails_deactivated' ),
|
||||
'wpcode-emails-deactivated',
|
||||
sprintf(
|
||||
// Translators: %1$s: opening anchor tag, %2$s: closing anchor tag. Link to docs about error notifications.
|
||||
esc_html__( 'Send an email when a snippet gets automatically deactivated? %1$sLearn more%2$s', 'insert-headers-and-footers' ),
|
||||
'<a href="' . esc_url( wpcode_utm_url( 'https://wpcode.com/docs/error-notifications/', 'settings', 'errors', 'deactivated' ) ) . '" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
1
|
||||
),
|
||||
'wpcode-emails-deactivated'
|
||||
);
|
||||
|
||||
$this->metabox_row(
|
||||
__( 'Send To', 'insert-headers-and-footers' ),
|
||||
$this->get_input_text(
|
||||
'wpcode-emails-deactivated-addresses',
|
||||
wpcode()->settings->get_option( 'emails_deactivated_addresses', get_option( 'admin_email' ) ),
|
||||
__( 'Enter a comma separated list of email addresses to receive deactivation notifications. Defaults to the admin email address.', 'insert-headers-and-footers' ),
|
||||
true
|
||||
),
|
||||
'wpcode-emails-deactivated-addresses'
|
||||
);
|
||||
|
||||
$preview_url = add_query_arg(
|
||||
array(
|
||||
'wpcode_email_template' => 'deactivated',
|
||||
'wpcode_email_preview' => '1',
|
||||
),
|
||||
admin_url()
|
||||
);
|
||||
|
||||
$this->metabox_row(
|
||||
'',
|
||||
'<a href="' . esc_url( $preview_url ) . '" class="wpcode-button wpcode-button-secondary" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Preview Email', 'insert-headers-and-footers' ) . '</a>',
|
||||
'wpcode-emails-deactivated-preview'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The error logging field.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function error_logging_field() {
|
||||
$this->metabox_row(
|
||||
__( 'Error Logging', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_toggle(
|
||||
wpcode()->settings->get_option( 'error_logging' ),
|
||||
'wpcode-error-logging',
|
||||
sprintf(
|
||||
// Translators: %1$s: opening anchor tag, %2$s: closing anchor tag.
|
||||
esc_html__( 'Log errors thrown by snippets? %1$sView Logs%2$s', 'insert-headers-and-footers' ),
|
||||
'<a href="' . esc_url( admin_url( 'admin.php?page=wpcode-tools&view=logs' ) ) . '">',
|
||||
'</a>'
|
||||
),
|
||||
1
|
||||
),
|
||||
'wpcode-error-logging'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The access management tab content.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function access_view_content() {
|
||||
?>
|
||||
<h2><?php esc_html_e( 'Access Control', 'insert-headers-and-footers' ); ?></h2>
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
// Translators: %1$s - Opening anchor tag. %2$s - Closing anchor tag.
|
||||
esc_html__( 'Select the user roles that are allowed to manage different types of snippets or parts of WPCode. By default, all permissions are provided only to administrator users. Please see our %1$sAccess Control documentation%2$s for more details.', 'insert-headers-and-footers' ),
|
||||
'<a href="' . esc_url( wpcode_utm_url( 'https://wpcode.com/docs/access-control/', 'settings-access-controls', 'access-controls-documentation' ) ) . '" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<hr/>
|
||||
<?php
|
||||
$capabilities = $this->get_capabilites();
|
||||
|
||||
foreach ( $capabilities as $capability => $capability_data ) {
|
||||
$selected_roles = wpcode()->settings->get_option( $capability, array() );
|
||||
$this->metabox_row(
|
||||
$capability_data['label'],
|
||||
$this->get_roles_dropdown( $selected_roles, 'wpcode_capability_' . $capability ) .
|
||||
'<p class="description">' . esc_html( $capability_data['description'] ) . '</p>'
|
||||
);
|
||||
}
|
||||
|
||||
$this->php_setting();
|
||||
|
||||
?>
|
||||
<button class="wpcode-button" type="submit">
|
||||
<?php esc_html_e( 'Save Changes', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Access control overlay.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_access_overlay() {
|
||||
$text = sprintf(
|
||||
// translators: %1$s and %2$s are <u> tags.
|
||||
'<p>' . esc_html__( 'Improve the way you and your team manage your snippets with the WPCode Access Control settings. Enable other users on your site to manage different types of snippets or configure Conversion Pixels settings and update configuration files. This feature is available on the %1$sWPCode Pro%2$s plan or higher.', 'insert-headers-and-footers' ) . '</p>',
|
||||
'<u>',
|
||||
'</u>'
|
||||
);
|
||||
|
||||
return self::get_upsell_box(
|
||||
esc_html__( 'Access Control is a PRO Feature', 'insert-headers-and-footers' ),
|
||||
$text,
|
||||
array(
|
||||
'text' => esc_html__( 'Upgrade to WPCode PRO', 'insert-headers-and-footers' ),
|
||||
'url' => esc_url( wpcode_utm_url( 'https://wpcode.com/lite/', 'settings', 'tab-' . $this->view, 'upgrade-to-pro' ) ),
|
||||
),
|
||||
array(),
|
||||
array(
|
||||
esc_html__( 'Save time and improve website management with your team', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Delegate snippet management to other users with full control', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Enable other users to set up ads & 3rd party services', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Choose if PHP snippets should be enabled on the site', 'insert-headers-and-footers' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the PHP disable setting.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function php_setting() {
|
||||
?>
|
||||
<h2><?php esc_html_e( 'PHP Snippets', 'insert-headers-and-footers' ); ?></h2>
|
||||
<?php
|
||||
$this->metabox_row(
|
||||
esc_html__( 'Disable PHP snippets', 'insert-headers-and-footers' ),
|
||||
$this->get_checkbox_toggle(
|
||||
boolval( wpcode()->settings->get_option( 'completely_disable_php' ) ),
|
||||
'completely_disable_php',
|
||||
esc_html__( 'This option will completely disable PHP snippets execution and the option to edit or add new PHP snippets.', 'insert-headers-and-footers' )
|
||||
),
|
||||
'wpcode_disable_php'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the custom capabilities.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function get_capabilites() {
|
||||
return wpcode_custom_capabilities();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a dropdown with the user roles.
|
||||
*
|
||||
* @param array $selected The roles that are selected.
|
||||
* @param string $name The name of the select.
|
||||
* @param string $id The ID of the select, defaults to the name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_roles_dropdown( $selected, $name, $id = '' ) {
|
||||
if ( empty( $id ) ) {
|
||||
$id = $name;
|
||||
}
|
||||
$user_roles = wp_roles()->roles;
|
||||
$dropdown = '<select name="' . esc_attr( $name ) . '[]" id="' . esc_attr( $id ) . '" class="wpcode-select2" multiple>';
|
||||
foreach ( $user_roles as $key => $user_role ) {
|
||||
if ( ! isset( $user_role['name'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$check_role = is_multisite() ? 'superadmin' : 'administrator';
|
||||
if ( $check_role === $key ) {
|
||||
continue;
|
||||
}
|
||||
$dropdown .= '<option value="' . esc_attr( $key ) . '" ' . selected( in_array( $key, $selected, true ), true, false ) . '>' . esc_html( $user_role['name'] ) . '</option>';
|
||||
}
|
||||
$dropdown .= '</select>';
|
||||
|
||||
return $dropdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a notice to suggest installing WP Mail SMTP.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function wp_mail_smtp_notice() {
|
||||
if ( function_exists( 'wp_mail_smtp' ) ) {
|
||||
return;
|
||||
}
|
||||
$dismissed_notices = get_option( 'wpcode_admin_notices', array() );
|
||||
$slug = 'emailsmtp';
|
||||
$smtp_url = add_query_arg(
|
||||
array(
|
||||
'type' => 'term',
|
||||
's' => 'wp mail smtp',
|
||||
'tab' => 'search',
|
||||
),
|
||||
admin_url( 'plugin-install.php' )
|
||||
);
|
||||
if ( ! isset( $dismissed_notices[ $slug ] ) || empty( $dismissed_notices[ $slug ]['dismissed'] ) ) {
|
||||
?>
|
||||
<div class="notice wpcode-notice notice-global is-dismissible" id="wpcode-notice-global-<?php echo esc_attr( $slug ); ?>">
|
||||
<h3><?php echo esc_html__( 'Make Sure Important Emails Reach Your Inbox', 'insert-headers-and-footers' ); ?></h3>
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
// Translators: %1$s: opening anchor tag, %2$s: closing anchor tag.
|
||||
esc_html__( 'Solve common email deliverability issues for good. %1$sGet WP Mail SMTP%2$s!', 'insert-headers-and-footers' ),
|
||||
'<a href="' . esc_url( $smtp_url ) . '">',
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
wpcode()->notice->enqueues();
|
||||
}
|
||||
}
|
||||
}
|
||||
+2723
File diff suppressed because it is too large
Load Diff
+1095
File diff suppressed because it is too large
Load Diff
+1394
File diff suppressed because it is too large
Load Diff
+1270
File diff suppressed because it is too large
Load Diff
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Trait for the library refresh button (lite version).
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Trait WPCode_Library_Refresh_Button.
|
||||
*/
|
||||
trait WPCode_Library_Refresh_Button {
|
||||
|
||||
/**
|
||||
* Add the "Check for Updates" button to the header.
|
||||
* Lite version - simple button without update check logic.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_check_for_updates_button() {
|
||||
$tooltip_text = esc_html__( 'Check for updates to your private library snippets.', 'insert-headers-and-footers' );
|
||||
|
||||
echo '<span class="wpcode-help-tooltip"><button type="button" id="wpcode-check-for-updates" class="wpcode-button-just-icon">' . wp_kses( get_wpcode_icon( 'sync', 16, 16, '0 0 20 21' ), wpcode_get_icon_allowed_tags() ) . '</button>';
|
||||
echo '<span class="wpcode-help-tooltip-text wpcode-help-tooltip-text-down wpcode-check-updates-tooltip">' . esc_html( $tooltip_text ) . '</span></span>';
|
||||
}
|
||||
}
|
||||
+250
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
trait WPCode_My_Library_Markup_Lite {
|
||||
|
||||
/**
|
||||
* Get an array of items for the library blurred background.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_placeholder_library_items() {
|
||||
$categories = array(
|
||||
'*' => 'Most Popular',
|
||||
'admin' => 'Admin',
|
||||
'archive' => 'Archive',
|
||||
'attachments' => 'Attachments',
|
||||
'comments' => 'Comments',
|
||||
'disable' => 'Disable',
|
||||
'login' => 'Login',
|
||||
'rss-feeds' => 'RSS Feeds',
|
||||
'search' => 'Search',
|
||||
);
|
||||
|
||||
$categories_parsed = array();
|
||||
foreach ( $categories as $slug => $name ) {
|
||||
$categories_parsed[] = array(
|
||||
'slug' => $slug,
|
||||
'name' => $name,
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'categories' => $categories_parsed,
|
||||
'snippets' => array(
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Add an Edit Post Link to Archives',
|
||||
'code' => '',
|
||||
'note' => 'Make it easier to edit posts when viewing archives. Or on single pages. If you...',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'archive',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Add Featured Images to RSS Feeds',
|
||||
'code' => '',
|
||||
'note' => 'Extend your site\'s RSS feeds by including featured images in the feed.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'rss-feeds',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Add the Page Slug to Body Class',
|
||||
'code' => '',
|
||||
'note' => 'Add the page slug to the body class for better styling.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'archive',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Allow SVG Files Upload',
|
||||
'code' => '',
|
||||
'note' => 'Add support for SVG files to be uploaded in WordPress media.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'most-popular',
|
||||
1 => 'attachments',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Automatically Link Featured Images to Posts',
|
||||
'code' => '',
|
||||
'note' => 'Wrap featured images in your theme in links to posts.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'attachments',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Change "Howdy Admin" in Admin Bar',
|
||||
'code' => '',
|
||||
'note' => 'Customize the "Howdy" message in the admin bar.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'admin',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Change Admin Panel Footer Text',
|
||||
'code' => '',
|
||||
'note' => 'Display custom text in the admin panel footer with this snippet.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'admin',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Change Excerpt Length',
|
||||
'code' => '',
|
||||
'note' => 'Update the length of the Excerpts on your website using this snippet.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'archive',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Change Read More Text for Excerpts',
|
||||
'code' => '',
|
||||
'note' => 'Customize the "Read More" text that shows up after excerpts.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'archive',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Completely Disable Comments',
|
||||
'code' => '',
|
||||
'note' => 'Disable comments for all post types, in the admin and the frontend.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'most-popular',
|
||||
1 => 'comments',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Delay Posts in RSS Feeds',
|
||||
'code' => '',
|
||||
'note' => 'Add a delay before published posts show up in the RSS feeds.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'rss-feeds',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Disable Attachment Pages',
|
||||
'code' => '',
|
||||
'note' => 'Hide the Attachment/Attachments pages on the frontend from all visitors.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'most-popular',
|
||||
1 => 'attachments',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Disable Automatic Updates',
|
||||
'code' => '',
|
||||
'note' => 'Use this snippet to completely disable automatic updates on your website.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'most-popular',
|
||||
1 => 'disable',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Disable Automatic Updates Emails',
|
||||
'code' => '',
|
||||
'note' => 'Stop getting emails about automatic updates on your WordPress site.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'most-popular',
|
||||
1 => 'disable',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
array(
|
||||
'library_id' => 0,
|
||||
'title' => 'Disable Gutenberg Editor (use Classic Editor)',
|
||||
'code' => '',
|
||||
'note' => 'Switch back to the Classic Editor by disablling the Block Editor.',
|
||||
'categories' =>
|
||||
array(
|
||||
0 => 'most-popular',
|
||||
1 => 'admin',
|
||||
),
|
||||
'code_type' => 'php',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get placeholder library items in a blurred box.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function blurred_placeholder_items() {
|
||||
$snippets = $this->get_placeholder_library_items();
|
||||
echo '<div class="wpcode-blur-area">';
|
||||
$this->get_library_markup( $snippets['categories'], $snippets['snippets'] );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the markup for the "My Library" section.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function get_my_library_markup() {
|
||||
$this->blurred_placeholder_items();
|
||||
// Show upsell.
|
||||
echo WPCode_Admin_Page::get_upsell_box( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
esc_html__( 'My Library is a PRO Feature', 'insert-headers-and-footers' ),
|
||||
'<p>' . esc_html__( 'Upgrade to WPCode PRO today and save your snippets in your private library directly from the plugin and import them with 1-click on other sites.', 'insert-headers-and-footers' ) . '</p>',
|
||||
array(
|
||||
'text' => esc_html__( 'Upgrade to PRO and Unlock "My Library"', 'insert-headers-and-footers' ),
|
||||
'url' => esc_url( wpcode_utm_url( 'https://wpcode.com/lite/', 'add-snippet', 'my-library', 'upgrade-and-unlock' ) ),
|
||||
),
|
||||
array(
|
||||
'text' => esc_html__( 'Learn more about all the features', 'insert-headers-and-footers' ),
|
||||
'url' => esc_url( wpcode_utm_url( 'https://wpcode.com/lite/', 'add-snippet', 'my-library', 'features' ) ),
|
||||
),
|
||||
array(
|
||||
esc_html__( 'Save your snippets to your library', 'insert-headers-and-footers' ),
|
||||
esc_html__( '1-click import snippets from you library', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Deploy new snippets from your account', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Update snippets across all your sites', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Set up new websites faster', 'insert-headers-and-footers' ),
|
||||
esc_html__( 'Edit snippets in the WPCode Library', 'insert-headers-and-footers' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
/**
|
||||
* Trait for displaying code revisions in the admin.
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Trait WPCode_Revisions_Display_Lite.
|
||||
*/
|
||||
trait WPCode_Revisions_Display_Lite {
|
||||
/**
|
||||
* Get a code revisions list with a notice on top.
|
||||
*
|
||||
* @param string $title The title for the notice.
|
||||
* @param string $description Description or text below the title.
|
||||
* @param array $button_1 Button 1 params for the get_upsell_box method.
|
||||
* @param array $button_2 Button 2 params for the get_upsell_box method.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function code_revisions_list_with_notice( $title, $description = '', $button_1 = array(), $button_2 = array() ) {
|
||||
$html = '<div class="wpcode-revisions-list-area">';
|
||||
|
||||
$html .= $this->get_code_revisions_empty_list();
|
||||
$html .= WPCode_Admin_Page::get_upsell_box(
|
||||
$title,
|
||||
$description,
|
||||
$button_1,
|
||||
$button_2
|
||||
);
|
||||
$html .= '</div>';// .wpcode-revisions-list-area.
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the markup for a revision item in the list of revisions.
|
||||
*
|
||||
* @param int $author_id The author id to display the avatar and name for.
|
||||
* @param string $date The date used to display time passed.
|
||||
* @param array $actions Links specific to this row.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_revision_item( $author_id, $date, $actions = array() ) {
|
||||
$list_item = '<li class="wpcode-revision-list-item">';
|
||||
if ( ! empty( $author_id ) ) {
|
||||
$list_item .= get_avatar( $author_id, 30 );
|
||||
$list_item .= sprintf(
|
||||
'<span class="wpcode-revision-list-author">%s</span>',
|
||||
get_the_author_meta( 'display_name', $author_id )
|
||||
);
|
||||
} else {
|
||||
$list_item .= sprintf(
|
||||
'<img src="%s" class="avatar avatar-30 photo" alt="Avatar" width="30" height="30" />',
|
||||
esc_url( WPCODE_PLUGIN_URL . 'admin/images/default-user-icon.png' )
|
||||
);
|
||||
$list_item .= '<span class="wpcode-revision-list-author">John Doe</span>';
|
||||
}
|
||||
$list_item .= sprintf(
|
||||
'<span class="wpcode-revision-list-date">%s</span>',
|
||||
$date
|
||||
);
|
||||
if ( ! empty( $actions ) ) {
|
||||
$list_item .= sprintf(
|
||||
'<span class="wpcode-revision-list-item-actions">%s</span>',
|
||||
implode( '', $actions )
|
||||
);
|
||||
}
|
||||
$list_item .= '</li>';
|
||||
|
||||
return $list_item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of code revisions to use behind the notice.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_code_revisions_empty_list() {
|
||||
$list = array();
|
||||
$post_modified = isset( $this->snippet ) ? strtotime( $this->snippet->get_post_data()->post_modified ) : time();
|
||||
$snippet_author = isset( $this->snippet ) ? $this->snippet->get_snippet_author() : get_current_user_id();
|
||||
$revisions_data = array(
|
||||
$post_modified,
|
||||
$post_modified - DAY_IN_SECONDS,
|
||||
$post_modified - WEEK_IN_SECONDS,
|
||||
$post_modified - 2 * WEEK_IN_SECONDS,
|
||||
$post_modified - MONTH_IN_SECONDS,
|
||||
$post_modified - 2 * MONTH_IN_SECONDS,
|
||||
);
|
||||
|
||||
$compare = sprintf(
|
||||
'<span>%s</span>',
|
||||
esc_html__( 'Compare', 'insert-headers-and-footers' )
|
||||
);
|
||||
$view = sprintf(
|
||||
'<span>%s</a>',
|
||||
get_wpcode_icon( 'eye', 16, 11, '0 0 16 11' )
|
||||
);
|
||||
|
||||
foreach ( $revisions_data as $revisions_date ) {
|
||||
$updated = sprintf(
|
||||
// Translators: time since the revision has been updated.
|
||||
esc_html__( 'Updated %s ago', 'insert-headers-and-footers' ),
|
||||
human_time_diff( $revisions_date )
|
||||
);
|
||||
|
||||
$list[] = $this->get_revision_item(
|
||||
0,
|
||||
$updated,
|
||||
array(
|
||||
$compare,
|
||||
$view,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$html = '<div class="wpcode-blur-area">';
|
||||
|
||||
$html .= sprintf(
|
||||
'<ul class="wpcode-revisions-list">%s</ul>',
|
||||
implode( '', $list )
|
||||
);
|
||||
|
||||
$button_text = sprintf(
|
||||
// Translators: The placeholder gets replaced with the extra number of revisions available.
|
||||
esc_html__( '%d Other Revisions', 'insert-headers-and-footers' ),
|
||||
3
|
||||
);
|
||||
|
||||
$html .= sprintf(
|
||||
'<button type="button" class="wpcode-button wpcode-button-secondary wpcode-button-icon" id="wpcode-show-all-snippets">%1$s %2$s</button>',
|
||||
get_wpcode_icon( 'rewind', 16, 14 ),
|
||||
$button_text
|
||||
);
|
||||
|
||||
$html .= '</div>';// .wpcode-blur-area.
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* WPConsent Notice Trait
|
||||
*
|
||||
* @package WPCode
|
||||
*/
|
||||
|
||||
trait WPCode_WPConsent_Notice {
|
||||
|
||||
/**
|
||||
* Display a notice to suggest WPConsent.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function notice_wpconsent() {
|
||||
if ( function_exists( 'wpconsent' ) ) {
|
||||
return;
|
||||
}
|
||||
$dismissed_notices = get_option( 'wpcode_admin_notices', array() );
|
||||
$slug = 'wpconsent_pixel';
|
||||
$smtp_url = add_query_arg(
|
||||
array(
|
||||
'type' => 'term',
|
||||
's' => 'wpconsent',
|
||||
'tab' => 'search',
|
||||
),
|
||||
admin_url( 'plugin-install.php' )
|
||||
);
|
||||
if ( ! isset( $dismissed_notices[ $slug ] ) || empty( $dismissed_notices[ $slug ]['dismissed'] ) ) {
|
||||
?>
|
||||
<div class="notice wpcode-notice notice-success notice-global is-dismissible" id="wpcode-notice-global-<?php echo esc_attr( $slug ); ?>">
|
||||
<h3><?php echo esc_html__( 'Using tracking scripts? Make Sure You’re Covered with a Cookie Banner!', 'insert-headers-and-footers' ); ?></h3>
|
||||
<p>
|
||||
<?php esc_html_e( 'Easily customize your own cookie banner and let our tools block cookies until users give consent. Scan and set up automatically!', 'insert-headers-and-footers' ); ?>
|
||||
</p>
|
||||
<p>
|
||||
<button class="wpcode-button wpcode-button-secondary wpcode-button-install-plugin" data-slug="wpconsent">
|
||||
<?php esc_html_e( 'Install WPConsent for Free', 'insert-headers-and-footers' ); ?>
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
wpcode()->notice->enqueues();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user