update
This commit is contained in:
@@ -0,0 +1,612 @@
|
||||
<?php
|
||||
if ( !class_exists( 'WP_List_Table' ) ) {
|
||||
include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
|
||||
}
|
||||
|
||||
class Hfcm_Snippets_List extends WP_List_Table
|
||||
{
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'singular' => esc_html__( 'Snippet', 'header-footer-code-manager' ),
|
||||
'plural' => esc_html__( 'Snippets', 'header-footer-code-manager' ),
|
||||
'ajax' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve snippets data from the database
|
||||
*
|
||||
* @param int $per_page
|
||||
* @param int $page_number
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_snippets( $per_page = 20, $page_number = 1, $customvar = 'all' )
|
||||
{
|
||||
|
||||
global $wpdb;
|
||||
$table_name = "{$wpdb->prefix}hfcm_scripts";
|
||||
$page_number = absint( $page_number );
|
||||
$per_page = absint( $per_page );
|
||||
$customvar = sanitize_text_field( $customvar );
|
||||
$orderby = 'script_id';
|
||||
$order = 'ASC';
|
||||
|
||||
if ( !empty( $_GET['orderby'] ) ) {
|
||||
$orderby = sanitize_sql_orderby( $_GET['orderby'] );
|
||||
if ( empty( $orderby ) || !in_array( $orderby, array( 'script_id', 'name', 'location' ) ) ) {
|
||||
$orderby = 'script_id';
|
||||
}
|
||||
}
|
||||
if ( !empty( $_GET['order'] ) ) {
|
||||
$order = strtolower( sanitize_sql_orderby( $_GET['order'] ) );
|
||||
if ( empty( $order ) || !in_array( $order, array( 'desc', 'asc' ) ) ) {
|
||||
$order = 'ASC';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM `{$table_name}` WHERE 1";
|
||||
$placeholder_args = array();
|
||||
if ( in_array( $customvar, array( 'inactive', 'active' ) ) ) {
|
||||
$sql .= " AND status = '%s'";
|
||||
$placeholder_args[] = $customvar;
|
||||
}
|
||||
if ( !empty( $_POST['snippet_type'] ) ) {
|
||||
if ( check_admin_referer( 'bulk-snippets' ) ) {
|
||||
$snippet_type = addslashes( sanitize_text_field( $_POST['snippet_type'] ) );
|
||||
if ( in_array( $snippet_type, array( 'html', 'css', 'js' ) ) ) {
|
||||
$sql .= " AND snippet_type = %s";
|
||||
$placeholder_args[] = $snippet_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !empty( $_POST['s'] ) ) {
|
||||
if ( check_admin_referer( 'bulk-snippets' ) ) {
|
||||
$search_query = addslashes( sanitize_text_field( $_POST['s'] ) );
|
||||
$sql .= " AND name LIKE %s";
|
||||
$placeholder_args[] = '%' . $search_query . '%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY %s %s LIMIT %d OFFSET %d';
|
||||
$placeholder_args[] = $orderby;
|
||||
$placeholder_args[] = $order;
|
||||
$placeholder_args[] = $per_page;
|
||||
$placeholder_args[] = ($page_number - 1) * $per_page;
|
||||
|
||||
if ( !empty( $placeholder_args ) ) {
|
||||
$sql = $wpdb->prepare( $sql, $placeholder_args );
|
||||
}
|
||||
$result = $wpdb->get_results(
|
||||
$sql, 'ARRAY_A'
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a snipppet record.
|
||||
*
|
||||
* @param int $id snippet ID
|
||||
*/
|
||||
public static function delete_snippet( $id )
|
||||
{
|
||||
$id = (int) $id;
|
||||
if ( empty( $id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
$table_name = "{$wpdb->prefix}hfcm_scripts";
|
||||
|
||||
$wpdb->delete(
|
||||
$table_name, array( 'script_id' => $id ), array( '%d' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate a snipppet record.
|
||||
*
|
||||
* @param int $id snippet ID
|
||||
*/
|
||||
public static function activate_snippet( $id )
|
||||
{
|
||||
|
||||
$id = (int) $id;
|
||||
if ( empty( $id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
$table_name = "{$wpdb->prefix}hfcm_scripts";
|
||||
|
||||
$wpdb->update(
|
||||
$table_name, array(
|
||||
'status' => 'active',
|
||||
), array( 'script_id' => $id ), array( '%s' ), array( '%d' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate a snipppet record.
|
||||
*
|
||||
* @param int $id snippet ID
|
||||
*/
|
||||
public static function deactivate_snippet( $id )
|
||||
{
|
||||
|
||||
$id = (int) $id;
|
||||
if ( empty( $id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
$table_name = "{$wpdb->prefix}hfcm_scripts";
|
||||
|
||||
$wpdb->update(
|
||||
$table_name, array(
|
||||
'status' => 'inactive',
|
||||
), array( 'script_id' => $id ), array( '%s' ), array( '%d' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the count of records in the database.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public static function record_count( $customvar = 'all' )
|
||||
{
|
||||
|
||||
global $wpdb;
|
||||
$table_name = "{$wpdb->prefix}hfcm_scripts";
|
||||
$sql = "SELECT COUNT(*) FROM `{$table_name}`";
|
||||
$placeholder_args = [];
|
||||
|
||||
$customvar = sanitize_text_field( $customvar );
|
||||
|
||||
if ( in_array( $customvar, array( 'inactive', 'active' ) ) ) {
|
||||
$sql .= " WHERE status = %s";
|
||||
$placeholder_args[] = $customvar;
|
||||
}
|
||||
if ( !empty( $placeholder_args ) ) {
|
||||
$sql = $wpdb->prepare( $sql, $placeholder_args );
|
||||
}
|
||||
|
||||
return $wpdb->get_var( $sql );
|
||||
}
|
||||
|
||||
/**
|
||||
* Text displayed when no snippet data is available
|
||||
*/
|
||||
public function no_items()
|
||||
{
|
||||
esc_html_e( 'No Snippets available.', 'header-footer-code-manager' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a column when no column specific method exist.
|
||||
*
|
||||
* @param array $item
|
||||
* @param string $column_name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function column_default( $item, $column_name )
|
||||
{
|
||||
|
||||
switch ( $column_name ) {
|
||||
case 'name':
|
||||
return esc_html( $item[ $column_name ] );
|
||||
|
||||
case 'display_on':
|
||||
$nnr_hfcm_display_array = array(
|
||||
'All' => esc_html__( 'Site Wide', 'header-footer-code-manager' ),
|
||||
's_posts' => esc_html__( 'Specific Posts', 'header-footer-code-manager' ),
|
||||
's_pages' => esc_html__( 'Specific Pages', 'header-footer-code-manager' ),
|
||||
's_categories' => esc_html__( 'Specific Categories', 'header-footer-code-manager' ),
|
||||
's_custom_posts' => esc_html__( 'Specific Custom Post Types', 'header-footer-code-manager' ),
|
||||
's_tags' => esc_html__( 'Specific Tags', 'header-footer-code-manager' ),
|
||||
's_is_home' => esc_html__( 'Home Page', 'header-footer-code-manager' ),
|
||||
's_is_search' => esc_html__( 'Search Page', 'header-footer-code-manager' ),
|
||||
's_is_archive' => esc_html__( 'Archive Page', 'header-footer-code-manager' ),
|
||||
'latest_posts' => esc_html__( 'Latest Posts', 'header-footer-code-manager' ),
|
||||
'manual' => esc_html__( 'Shortcode Only', 'header-footer-code-manager' ),
|
||||
);
|
||||
|
||||
if ( 's_posts' === $item[ $column_name ] ) {
|
||||
|
||||
$empty = 1;
|
||||
$s_posts = json_decode( $item['s_posts'] );
|
||||
|
||||
foreach ( $s_posts as $id ) {
|
||||
$id = absint( $id );
|
||||
if ( 'publish' === get_post_status( $id ) ) {
|
||||
$empty = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( $empty ) {
|
||||
return '<span class="hfcm-red">' . esc_html__( 'No post selected', 'header-footer-code-manager' ) . '</span>';
|
||||
}
|
||||
}
|
||||
|
||||
return esc_html( $nnr_hfcm_display_array[ $item[ $column_name ] ] );
|
||||
|
||||
case 'location':
|
||||
|
||||
if ( !$item[ $column_name ] ) {
|
||||
return esc_html__( 'N/A', 'header-footer-code-manager' );
|
||||
}
|
||||
|
||||
$nnr_hfcm_locations = array(
|
||||
'header' => esc_html__( 'Header', 'header-footer-code-manager' ),
|
||||
'before_content' => esc_html__( 'Before Content', 'header-footer-code-manager' ),
|
||||
'after_content' => esc_html__( 'After Content', 'header-footer-code-manager' ),
|
||||
'footer' => esc_html__( 'Footer', 'header-footer-code-manager' ),
|
||||
);
|
||||
return esc_html( $nnr_hfcm_locations[ $item[ $column_name ] ] );
|
||||
|
||||
case 'device_type':
|
||||
|
||||
if ( 'both' === $item[ $column_name ] ) {
|
||||
return esc_html__( 'Show on All Devices', 'header-footer-code-manager' );
|
||||
} elseif ( 'mobile' === $item[ $column_name ] ) {
|
||||
return esc_html__( 'Only Mobile Devices', 'header-footer-code-manager' );
|
||||
} elseif ( 'desktop' === $item[ $column_name ] ) {
|
||||
return esc_html__( 'Only Desktop', 'header-footer-code-manager' );
|
||||
} else {
|
||||
return esc_html( $item[ $column_name ] );
|
||||
}
|
||||
case 'snippet_type':
|
||||
$snippet_types = array(
|
||||
'html' => esc_html__( 'HTML', 'header-footer-code-manager' ),
|
||||
'css' => esc_html__( 'CSS', 'header-footer-code-manager' ),
|
||||
'js' => esc_html__( 'Javascript', 'header-footer-code-manager' )
|
||||
);
|
||||
return esc_html( $snippet_types[ $item[ $column_name ] ] );
|
||||
|
||||
case 'status':
|
||||
|
||||
if ( 'inactive' === $item[ $column_name ] ) {
|
||||
return '<div class="nnr-switch">
|
||||
<label for="nnr-round-toggle' . esc_attr( $item['script_id'] ) . '">OFF</label>
|
||||
<input id="nnr-round-toggle' . esc_attr( $item['script_id'] ) . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . esc_attr( $item['script_id'] ) . '" />
|
||||
<label for="nnr-round-toggle' . esc_attr( $item['script_id'] ) . '"></label>
|
||||
<label for="nnr-round-toggle' . esc_attr( $item['script_id'] ) . '">ON</label>
|
||||
</div>
|
||||
';
|
||||
} elseif ( 'active' === $item[ $column_name ] ) {
|
||||
return '<div class="nnr-switch">
|
||||
<label for="nnr-round-toggle' . esc_attr( $item['script_id'] ) . '">OFF</label>
|
||||
<input id="nnr-round-toggle' . esc_attr( $item['script_id'] ) . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . esc_attr( $item['script_id'] ) . '" checked="checked" />
|
||||
<label for="nnr-round-toggle' . esc_attr( $item['script_id'] ) . '"></label>
|
||||
<label for="nnr-round-toggle' . esc_attr( $item['script_id'] ) . '">ON</label>
|
||||
</div>
|
||||
';
|
||||
} else {
|
||||
return esc_html( $item[ $column_name ] );
|
||||
}
|
||||
|
||||
case 'script_id':
|
||||
return esc_html( $item[ $column_name ] );
|
||||
|
||||
case 'shortcode':
|
||||
return '[hfcm id="' . absint( $item['script_id'] ) . '"]';
|
||||
|
||||
default:
|
||||
return print_r( $item, true ); // Show the whole array for troubleshooting purposes
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the bulk edit checkbox
|
||||
*
|
||||
* @param array $item
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function column_cb( $item )
|
||||
{
|
||||
return sprintf(
|
||||
'<input type="checkbox" name="snippets[]" value="%s" />', $item['script_id']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for name column
|
||||
*
|
||||
* @param array $item an array of DB data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function column_name( $item )
|
||||
{
|
||||
|
||||
$delete_nonce = wp_create_nonce( 'hfcm_delete_snippet' );
|
||||
$edit_nonce = wp_create_nonce( 'hfcm_edit_snippet' );
|
||||
|
||||
$title = '<strong>' . esc_html( $item['name'] ) . '</strong>';
|
||||
|
||||
$nnr_current_screen = get_current_screen();
|
||||
|
||||
if ( !empty( $nnr_current_screen->parent_base ) ) {
|
||||
$page = $nnr_current_screen->parent_base;
|
||||
} else {
|
||||
$page = sanitize_text_field( $_GET['page'] );
|
||||
}
|
||||
$actions = array(
|
||||
'edit' => sprintf( '<a href="?page=%s&action=%s&id=%s&_wpnonce=%s">' . esc_html__( 'Edit', 'header-footer-code-manager' ) . '</a>', esc_attr( 'hfcm-update' ), 'edit', absint( $item['script_id'] ), $edit_nonce ),
|
||||
'copy' => sprintf( '<a href="javascript:void(0);" data-shortcode=\'[hfcm id="%s"]\' class="hfcm_copy_shortcode" id="hfcm_copy_shortcode_%s">' . esc_html__( 'Copy Shortcode', 'header-footer-code-manager' ) . '</a>', absint( $item['script_id'] ), absint( $item['script_id'] ) ),
|
||||
'delete' => sprintf( '<a href="?page=%s&action=%s&snippet=%s&_wpnonce=%s">' . esc_html__( 'Delete', 'header-footer-code-manager' ) . '</a>', $page, 'delete', absint( $item['script_id'] ), $delete_nonce ),
|
||||
);
|
||||
|
||||
return $title . $this->row_actions( $actions );
|
||||
}
|
||||
|
||||
/**
|
||||
* Associative array of columns
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_columns()
|
||||
{
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'script_id' => esc_html__( 'ID', 'header-footer-code-manager' ),
|
||||
'status' => esc_html__( 'Status', 'header-footer-code-manager' ),
|
||||
'name' => esc_html__( 'Snippet Name', 'header-footer-code-manager' ),
|
||||
'display_on' => esc_html__( 'Display On', 'header-footer-code-manager' ),
|
||||
'location' => esc_html__( 'Location', 'header-footer-code-manager' ),
|
||||
'snippet_type' => esc_html__( 'Snippet Type', 'header-footer-code-manager' ),
|
||||
'device_type' => esc_html__( 'Devices', 'header-footer-code-manager' ),
|
||||
'shortcode' => esc_html__( 'Shortcode', 'header-footer-code-manager' ),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Columns to make sortable.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sortable_columns()
|
||||
{
|
||||
|
||||
return array(
|
||||
'name' => array( 'name', true ),
|
||||
'location' => array( 'location', true ),
|
||||
'script_id' => array( 'script_id', false ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an associative array containing the bulk action
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_bulk_actions()
|
||||
{
|
||||
|
||||
return array(
|
||||
'bulk-activate' => esc_html__( 'Activate', 'header-footer-code-manager' ),
|
||||
'bulk-deactivate' => esc_html__( 'Deactivate', 'header-footer-code-manager' ),
|
||||
'bulk-delete' => esc_html__( 'Remove', 'header-footer-code-manager' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add filters and extra actions above and below the table
|
||||
*
|
||||
* @param string $which Are the actions displayed on the table top or bottom
|
||||
*/
|
||||
public function extra_tablenav( $which )
|
||||
{
|
||||
if ( 'top' === $which ) {
|
||||
$query = isset( $_POST['snippet_type'] ) ? sanitize_text_field( $_POST['snippet_type'] ) : '';
|
||||
$snippet_type = array(
|
||||
'html' => esc_html__( 'HTML', 'header-footer-code-manager' ),
|
||||
'css' => esc_html__( 'CSS', 'header-footer-code-manager' ),
|
||||
'js' => esc_html__( 'Javascript', 'header-footer-code-manager' )
|
||||
);
|
||||
|
||||
echo '<div class="alignleft actions">';
|
||||
echo '<select name="snippet_type">';
|
||||
echo '<option value="">' . esc_html__( 'All Snippet Types', 'header-footer-code-manager' ) . '</option>';
|
||||
|
||||
foreach ( $snippet_type as $key_type => $type ) {
|
||||
if ( $key_type == $query ) {
|
||||
echo '<option value="' . esc_attr( $key_type ) . '" selected>' . esc_html( $type ) . '</option>';
|
||||
} else {
|
||||
echo '<option value="' . esc_attr( $key_type ) . '">' . esc_html( $type ) . '</option>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '</select>';
|
||||
submit_button( __( 'Filter', 'header-footer-code-manager' ), 'button', 'filter_action', false );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '<div class="alignleft actions">';
|
||||
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles data query and filter, sorting, and pagination.
|
||||
*/
|
||||
public function prepare_items()
|
||||
{
|
||||
|
||||
$columns = $this->get_columns();
|
||||
$hidden = array();
|
||||
$sortable = $this->get_sortable_columns();
|
||||
|
||||
// Retrieve $customvar for use in query to get items.
|
||||
$customvar = 'all';
|
||||
if ( !empty( $_GET['customvar'] ) ) {
|
||||
$customvar = sanitize_text_field( $_GET['customvar'] );
|
||||
if ( empty( $customvar ) || !in_array( $customvar, [ 'inactive', 'active', 'all' ] ) ) {
|
||||
$customvar = 'all';
|
||||
}
|
||||
}
|
||||
$this->_column_headers = array( $columns, $hidden, $sortable );
|
||||
|
||||
/**
|
||||
* Process bulk action
|
||||
*/
|
||||
$this->process_bulk_action();
|
||||
$this->views();
|
||||
$per_page = $this->get_items_per_page( 'snippets_per_page', 20 );
|
||||
$current_page = $this->get_pagenum();
|
||||
$total_items = self::record_count();
|
||||
|
||||
$this->set_pagination_args(
|
||||
array(
|
||||
'total_items' => $total_items,
|
||||
'per_page' => $per_page,
|
||||
)
|
||||
);
|
||||
|
||||
$this->items = self::get_snippets( $per_page, $current_page, $customvar );
|
||||
}
|
||||
|
||||
public function get_views()
|
||||
{
|
||||
$views = array();
|
||||
$current = 'all';
|
||||
if ( !empty( $_GET['customvar'] ) ) {
|
||||
$current = sanitize_text_field( $_GET['customvar'] );
|
||||
}
|
||||
|
||||
//All link
|
||||
$class = 'all' === $current ? 'current' : '';
|
||||
$all_url = remove_query_arg( 'customvar' );
|
||||
$views['all'] = '<a href="' . esc_html( $all_url ) . '" class="' . esc_html( $class ) . '">' . esc_html__( 'All', 'header-footer-code-manager' ) . ' (' . esc_html__( $this->record_count() ) . ')</a>';
|
||||
|
||||
//Foo link
|
||||
$foo_url = add_query_arg( 'customvar', 'active' );
|
||||
$class = ('active' === $current ? 'current' : '');
|
||||
$views['active'] = '<a href="' . esc_html( $foo_url ) . '" class="' . esc_html( $class ) . '">' . esc_html__( 'Active', 'header-footer-code-manager' ) . ' (' . esc_html__( $this->record_count( 'active' ) ) . ')</a>';
|
||||
|
||||
//Bar link
|
||||
$bar_url = add_query_arg( 'customvar', 'inactive' );
|
||||
$class = ('inactive' === $current ? 'current' : '');
|
||||
$views['inactive'] = '<a href="' . esc_html( $bar_url ) . '" class="' . esc_html( $class ) . '">' . esc_html__( 'Inactive', 'header-footer-code-manager' ) . ' (' . esc_html__( $this->record_count( 'inactive' ) ) . ')</a>';
|
||||
|
||||
return $views;
|
||||
}
|
||||
|
||||
public function process_bulk_action()
|
||||
{
|
||||
//Detect when a bulk action is being triggered...
|
||||
if ( 'delete' === $this->current_action() ) {
|
||||
|
||||
if(!empty($_REQUEST['_wpnonce'])) {
|
||||
// In our file that handles the request, verify the nonce.
|
||||
$nonce = sanitize_text_field( $_REQUEST['_wpnonce'] );
|
||||
|
||||
if ( !wp_verify_nonce( $nonce, 'hfcm_delete_snippet' ) ) {
|
||||
die( 'Go get a life script kiddies' );
|
||||
} else {
|
||||
if ( !empty( $_GET['snippet'] ) ) {
|
||||
$snippet_id = absint( $_GET['snippet'] );
|
||||
if ( !empty( $snippet_id ) ) {
|
||||
self::delete_snippet( $snippet_id );
|
||||
}
|
||||
}
|
||||
|
||||
NNR_HFCM::hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the delete bulk action is triggered
|
||||
if ( (isset( $_POST['action'] ) && 'bulk-delete' === $_POST['action'])
|
||||
|| (isset( $_POST['action2'] ) && 'bulk-delete' === $_POST['action2'])
|
||||
) {
|
||||
if ( check_admin_referer( 'bulk-snippets' ) ) {
|
||||
$bulk_snippets = $_POST['snippets'];
|
||||
// loop over the array of record IDs and delete them
|
||||
foreach ( $bulk_snippets as $id ) {
|
||||
$id = absint( $id );
|
||||
if ( !empty( $id ) && is_int( $id ) ) {
|
||||
self::delete_snippet( $id );
|
||||
}
|
||||
}
|
||||
|
||||
NNR_HFCM::hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
|
||||
return;
|
||||
}
|
||||
} elseif ( (isset( $_POST['action'] ) && 'bulk-activate' === $_POST['action'])
|
||||
|| (isset( $_POST['action2'] ) && 'bulk-activate' === $_POST['action2'])
|
||||
) {
|
||||
if ( check_admin_referer( 'bulk-snippets' ) ) {
|
||||
$bulk_snippets = $_POST['snippets'];
|
||||
// loop over the array of record IDs and activate them
|
||||
foreach ( $bulk_snippets as $id ) {
|
||||
$id = absint( $id );
|
||||
if ( !empty( $id ) && is_int( $id ) ) {
|
||||
self::activate_snippet( $id );
|
||||
}
|
||||
}
|
||||
|
||||
NNR_HFCM::hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
|
||||
return;
|
||||
}
|
||||
} elseif ( (isset( $_POST['action'] ) && 'bulk-deactivate' === $_POST['action'])
|
||||
|| (isset( $_POST['action2'] ) && 'bulk-deactivate' === $_POST['action2'])
|
||||
) {
|
||||
if ( check_admin_referer( 'bulk-snippets' ) ) {
|
||||
$bulk_snippets = $_POST['snippets'];
|
||||
// loop over the array of record IDs and deactivate them
|
||||
foreach ( $bulk_snippets as $id ) {
|
||||
$id = absint( $id );
|
||||
if ( !empty( $id ) && is_int( $id ) ) {
|
||||
self::deactivate_snippet( $id );
|
||||
}
|
||||
}
|
||||
|
||||
NNR_HFCM::hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the search box.
|
||||
*
|
||||
* @param string $text The 'submit' button label.
|
||||
* @param string $input_id ID attribute value for the search input field.
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public function search_box( $text, $input_id )
|
||||
{
|
||||
if ( empty( $_REQUEST['s'] ) && !$this->has_items() ) {
|
||||
return;
|
||||
}
|
||||
$input_id = $input_id . '-search-input';
|
||||
?>
|
||||
<p class="search-box">
|
||||
<label class="screen-reader-text"
|
||||
for="<?php echo esc_attr( $input_id ); ?>"><?php echo esc_html( $text ); ?>:</label>
|
||||
<input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s"
|
||||
value="<?php esc_attr( _admin_search_query() ); ?>"/>
|
||||
<?php submit_button( $text, '', '', false, array( 'id' => 'search-submit' ) ); ?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,460 @@
|
||||
<?php
|
||||
|
||||
// Register the script
|
||||
wp_register_script( 'hfcm_showboxes', plugins_url( 'js/nnr-hfcm-showboxes.js', dirname( __FILE__ ) ), array( 'jquery' ) );
|
||||
|
||||
// prepare ID (for AJAX)
|
||||
if ( !isset( $id ) ) {
|
||||
$id = -1;
|
||||
}
|
||||
|
||||
// Localize the script with new data
|
||||
$translation_array = array(
|
||||
'header' => __( 'Header', 'header-footer-code-manager' ),
|
||||
'before_content' => __( 'Before Content', 'header-footer-code-manager' ),
|
||||
'after_content' => __( 'After Content', 'header-footer-code-manager' ),
|
||||
'footer' => __( 'Footer', 'header-footer-code-manager' ),
|
||||
'id' => absint( $id ),
|
||||
'security' => wp_create_nonce( 'hfcm-get-posts' ),
|
||||
);
|
||||
wp_localize_script( 'hfcm_showboxes', 'hfcm_localize', $translation_array );
|
||||
|
||||
// Enqueued script with localized data.
|
||||
wp_enqueue_script( 'hfcm_showboxes' );
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1>
|
||||
<?php echo $update ? esc_html__( 'Edit Snippet', 'header-footer-code-manager' ) : esc_html__( 'Add New Snippet', 'header-footer-code-manager' ) ?>
|
||||
<?php if ( $update ) : ?>
|
||||
<a href="<?php echo admin_url( 'admin.php?page=hfcm-create' ) ?>" class="page-title-action">
|
||||
<?php esc_html_e( 'Add New Snippet', 'header-footer-code-manager' ) ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</h1>
|
||||
<?php
|
||||
if ( !empty( $_GET['message'] ) ) :
|
||||
if ( 1 === $_GET['message'] ) :
|
||||
?>
|
||||
<div class="updated">
|
||||
<p><?php esc_html_e( 'Script updated', 'header-footer-code-manager' ); ?></p>
|
||||
</div>
|
||||
<a href="<?php echo admin_url( 'admin.php?page=hfcm-list' ) ?>">« <?php esc_html_e( 'Back to list', 'header-footer-code-manager' ); ?></a>
|
||||
<?php elseif ( 6 === $_GET['message'] ) : ?>
|
||||
<div class="updated">
|
||||
<p><?php esc_html_e( 'Script Added Successfully', 'header-footer-code-manager' ); ?></p>
|
||||
</div>
|
||||
<a href="<?php echo admin_url( 'admin.php?page=hfcm-list' ) ?>">« <?php esc_html_e( 'Back to list', 'header-footer-code-manager' ); ?></a>
|
||||
<?php
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $update ) :
|
||||
$hfcm_form_action = admin_url( 'admin.php?page=hfcm-request-handler&id=' . absint( $id ) );
|
||||
else :
|
||||
$hfcm_form_action = admin_url( 'admin.php?page=hfcm-request-handler' );
|
||||
endif;
|
||||
?>
|
||||
<form method="post" action="<?php echo $hfcm_form_action ?>">
|
||||
<?php
|
||||
if ( $update ) :
|
||||
wp_nonce_field( 'update-snippet_' . absint( $id ) );
|
||||
else :
|
||||
wp_nonce_field( 'create-snippet' );
|
||||
endif;
|
||||
?>
|
||||
<table class="wp-list-table widefat fixed hfcm-form-width form-table">
|
||||
<tr>
|
||||
<th class="hfcm-th-width"><?php esc_html_e( 'Snippet Name', 'header-footer-code-manager' ); ?></th>
|
||||
<td>
|
||||
<input type="text" name="data[name]" value="<?php echo esc_attr( $name ); ?>"
|
||||
class="hfcm-field-width"/>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$nnr_hfcm_snippet_type_array = array(
|
||||
'html' => esc_html__( 'HTML', 'header-footer-code-manager' ),
|
||||
'css' => esc_html__( 'CSS', 'header-footer-code-manager' ),
|
||||
'js' => esc_html__( 'Javascript', 'header-footer-code-manager' )
|
||||
); ?>
|
||||
<tr id="snippet_type">
|
||||
<th class="hfcm-th-width">
|
||||
<?php esc_html_e( 'Snippet Type', 'header-footer-code-manager' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<select name="data[snippet_type]">
|
||||
<?php
|
||||
foreach ( $nnr_hfcm_snippet_type_array as $nnr_key => $nnr_item ) {
|
||||
if ( $nnr_key === $nnr_snippet_type ) {
|
||||
echo "<option value='" . esc_attr( $nnr_key ) . "' selected>" . esc_html( $nnr_item ) . "</option>";
|
||||
} else {
|
||||
echo "<option value='" . esc_attr( $nnr_key ) . "'>" . esc_html( $nnr_item ) . "</option>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$nnr_hfcm_display_array = array(
|
||||
'All' => esc_html__( 'Site Wide', 'header-footer-code-manager' ),
|
||||
's_posts' => esc_html__( 'Specific Posts', 'header-footer-code-manager' ),
|
||||
's_pages' => esc_html__( 'Specific Pages', 'header-footer-code-manager' ),
|
||||
's_categories' => esc_html__( 'Specific Categories (Archive & Posts)', 'header-footer-code-manager' ),
|
||||
's_custom_posts' => esc_html__( 'Specific Post Types (Archive & Posts)', 'header-footer-code-manager' ),
|
||||
's_tags' => esc_html__( 'Specific Tags (Archive & Posts)', 'header-footer-code-manager' ),
|
||||
's_is_home' => esc_html__( 'Home Page', 'header-footer-code-manager' ),
|
||||
's_is_search' => esc_html__( 'Search Page', 'header-footer-code-manager' ),
|
||||
's_is_archive' => esc_html__( 'Archive Page', 'header-footer-code-manager' ),
|
||||
'latest_posts' => esc_html__( 'Latest Posts', 'header-footer-code-manager' ),
|
||||
'manual' => esc_html__( 'Shortcode Only', 'header-footer-code-manager' ),
|
||||
); ?>
|
||||
<tr>
|
||||
<th class="hfcm-th-width"><?php esc_html_e( 'Site Display', 'header-footer-code-manager' ); ?></th>
|
||||
<td>
|
||||
<select name="data[display_on]" onchange="hfcm_showotherboxes(this.value);">
|
||||
<?php
|
||||
foreach ( $nnr_hfcm_display_array as $dkey => $statusv ) {
|
||||
if ( $display_on === $dkey ) {
|
||||
printf( '<option value="%1$s" selected="selected">%2$s</option>', $dkey, $statusv );
|
||||
} else {
|
||||
printf( '<option value="%1$s">%2$s</option>', $dkey, $statusv );
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$nnr_hfcm_pages = get_pages();
|
||||
$nnr_hfcm_exclude_pages_style = ('s_pages' === $display_on) ? 'display:none;' : '';
|
||||
$nnr_hfcm_exclude_posts_style = ('s_posts' === $display_on) ? 'display:none;' : '';
|
||||
$nnr_hfcm_exclude_categories_style = 's_categories' === $display_on ? 'display:none;' : '';
|
||||
$nnr_hfcm_exclude_tags_style = 's_tags' === $display_on ? 'display:none;' : '';
|
||||
$nnr_hfcm_exclude_custom_posts_style = 's_custom_posts' === $display_on ? 'display:none;' : '';
|
||||
$nnr_hfcm_exclude_lp_count_style = 'latest_posts' === $display_on ? 'display:none;' : '';
|
||||
$nnr_hfcm_exclude_manual_style = 'manual' === $display_on ? 'display:none;' : '';
|
||||
?>
|
||||
<tr id="ex_pages"
|
||||
style="<?php echo esc_attr( $nnr_hfcm_exclude_pages_style . $nnr_hfcm_exclude_posts_style . $nnr_hfcm_exclude_tags_style . $nnr_hfcm_exclude_custom_posts_style . $nnr_hfcm_exclude_categories_style . $nnr_hfcm_exclude_lp_count_style . $nnr_hfcm_exclude_manual_style ); ?>">
|
||||
<th class="hfcm-th-width"><?php esc_html_e( 'Exclude Pages', 'header-footer-code-manager' ); ?></th>
|
||||
<td>
|
||||
<select name="data[ex_pages][]" multiple>
|
||||
<?php
|
||||
foreach ( $nnr_hfcm_pages as $pdata ) {
|
||||
if ( in_array( $pdata->ID, $ex_pages ) ) {
|
||||
printf( '<option value="%1$s" selected="selected">%2$s</option>', $pdata->ID, $pdata->post_title );
|
||||
} else {
|
||||
printf( '<option value="%1$s">%2$s</option>', $pdata->ID, $pdata->post_title );
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="ex_posts"
|
||||
style="<?php echo esc_attr( $nnr_hfcm_exclude_pages_style . $nnr_hfcm_exclude_posts_style . $nnr_hfcm_exclude_tags_style . $nnr_hfcm_exclude_custom_posts_style . $nnr_hfcm_exclude_categories_style . $nnr_hfcm_exclude_lp_count_style . $nnr_hfcm_exclude_manual_style ); ?>">
|
||||
<th class="hfcm-th-width"><?php esc_html_e( 'Exclude Posts', 'header-footer-code-manager' ); ?></th>
|
||||
<td>
|
||||
<select class="nnr-wraptext" name="data[ex_posts][]" multiple>
|
||||
<option disabled></option>
|
||||
</select> <img id="loader"
|
||||
src="<?php echo plugins_url( 'images/ajax-loader.gif', dirname( __FILE__ ) ); ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$nnr_hfcm_pages = get_pages();
|
||||
$nnr_hfcm_pages_style = ('s_pages' === $display_on) ? '' : 'display:none;';
|
||||
?>
|
||||
<tr id="s_pages" style="<?php echo esc_attr( $nnr_hfcm_pages_style ); ?>">
|
||||
<th class="hfcm-th-width">
|
||||
<?php esc_html_e( 'Page List', 'header-footer-code-manager' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<select name="data[s_pages][]" multiple>
|
||||
<?php
|
||||
foreach ( $nnr_hfcm_pages as $pdata ) {
|
||||
if ( in_array( $pdata->ID, $s_pages ) ) {
|
||||
printf( '<option value="%1$s" selected="selected">%2$s</option>', esc_attr( $pdata->ID ), esc_attr( $pdata->post_title ) );
|
||||
} else {
|
||||
printf( '<option value="%1$s">%2$s</option>', esc_attr( $pdata->ID ), esc_attr( $pdata->post_title ) );
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php $nnr_hfcm_posts_style = 's_posts' === $display_on ? '' : 'display:none;'; ?>
|
||||
<tr id="s_posts" style="<?php echo esc_attr( $nnr_hfcm_posts_style ); ?>">
|
||||
<th class="hfcm-th-width">
|
||||
<?php esc_html_e( 'Post List', 'header-footer-code-manager' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<select class="nnr-wraptext" name="data[s_posts][]" multiple>
|
||||
<option disabled>...</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$nnr_hfcm_categories = NNR_HFCM::hfcm_get_categories();
|
||||
$nnr_hfcm_tags = NNR_HFCM::hfcm_get_tags();
|
||||
|
||||
$nnr_hfcm_categories_style = 's_categories' === $display_on ? '' : 'display:none;';
|
||||
$nnr_hfcm_tags_style = 's_tags' === $display_on ? '' : 'display:none;';
|
||||
$nnr_hfcm_custom_posts_style = 's_custom_posts' === $display_on ? '' : 'display:none;';
|
||||
$nnr_hfcm_lpcount_style = 'latest_posts' === $display_on ? '' : 'display:none;';
|
||||
$nnr_hfcm_location_style = 'manual' === $display_on ? 'display:none;' : '';
|
||||
|
||||
// Get all names of Post Types
|
||||
$args = array(
|
||||
'public' => true,
|
||||
);
|
||||
|
||||
$output = 'names';
|
||||
$operator = 'and';
|
||||
|
||||
$nnr_hfcm_custom_post_types = get_post_types( $args, $output, $operator );
|
||||
$nnr_hfcm_post_types = array( 'post' );
|
||||
foreach ( $nnr_hfcm_custom_post_types as $cpdata ) {
|
||||
$nnr_hfcm_post_types[] = $cpdata;
|
||||
}
|
||||
?>
|
||||
<tr id="s_categories" style="<?php echo esc_attr( $nnr_hfcm_categories_style ); ?>">
|
||||
<th class="hfcm-th-width"><?php esc_html_e( 'Category List', 'header-footer-code-manager' ); ?></th>
|
||||
<td>
|
||||
<select name="data[s_categories][]" multiple>
|
||||
<?php
|
||||
foreach ( $nnr_hfcm_categories as $nnr_key_cat => $nnr_item_cat ) {
|
||||
foreach ( $nnr_item_cat['terms'] as $nnr_item_cat_key => $nnr_item_cat_term ) {
|
||||
if ( in_array( $nnr_item_cat_term->term_id, $s_categories ) ) {
|
||||
echo "<option value='" . esc_attr( $nnr_item_cat_term->term_id ) . "' selected>" . esc_html( $nnr_item_cat['name'] ) . " - " . esc_html( $nnr_item_cat_term->name ) . "</option>";
|
||||
} else {
|
||||
echo "<option value='" . esc_attr( $nnr_item_cat_term->term_id ) . "'>" . esc_html( $nnr_item_cat['name'] ) . " - " . esc_html( $nnr_item_cat_term->name ) . "</option>";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="s_tags" style="<?php echo esc_attr( $nnr_hfcm_tags_style ); ?>">
|
||||
<th class="hfcm-th-width"><?php esc_html_e( 'Tags List', 'header-footer-code-manager' ); ?></th>
|
||||
<td>
|
||||
<select name="data[s_tags][]" multiple>
|
||||
<?php
|
||||
foreach ( $nnr_hfcm_tags as $nnr_key_cat => $nnr_item_tag ) {
|
||||
foreach ( $nnr_item_tag['terms'] as $nnr_item_tag_key => $nnr_item_tag_term ) {
|
||||
if ( in_array( $nnr_item_tag_term->term_id, $s_tags ) ) {
|
||||
echo "<option value='" . esc_attr( $nnr_item_tag_term->term_id ) . "' selected>" . esc_html( $nnr_item_tag['name'] ) . " - " . esc_html( $nnr_item_tag_term->name ) . "</option>";
|
||||
} else {
|
||||
echo "<option value='" . esc_attr( $nnr_item_tag_term->term_id ) . "'>" . esc_html( $nnr_item_tag['name'] ) . " - " . esc_html( $nnr_item_tag_term->name ) . "</option>";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="c_posttype" style="<?php echo esc_attr( $nnr_hfcm_custom_posts_style ); ?>">
|
||||
<th class="hfcm-th-width"><?php esc_html_e( 'Post Types', 'header-footer-code-manager' ); ?></th>
|
||||
<td>
|
||||
<select name="data[s_custom_posts][]" multiple>
|
||||
<?php
|
||||
foreach ( $nnr_hfcm_custom_post_types as $cpkey => $cpdata ) {
|
||||
if ( in_array( $cpkey, $s_custom_posts ) ) {
|
||||
echo "<option value='" . esc_attr( $cpkey ) . "' selected>" . esc_html( $cpdata ) . "</option>";
|
||||
} else {
|
||||
echo "<option value='" . esc_attr( $cpkey ) . "'>" . esc_html( $cpdata ) . "</option>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="lp_count" style="<?php echo esc_attr( $nnr_hfcm_lpcount_style ); ?>">
|
||||
<th class="hfcm-th-width"><?php esc_html_e( 'Post Count', 'header-footer-code-manager' ); ?></th>
|
||||
<td>
|
||||
<select name="data[lp_count]">
|
||||
<?php
|
||||
for ( $i = 1; $i <= 20; $i++ ) {
|
||||
if ( $i == $lp_count ) {
|
||||
echo "<option value='" . esc_attr( $i ) . "' selected>" . esc_html( $i ) . "</option>";
|
||||
} else {
|
||||
echo "<option value='" . esc_attr( $i ) . "'>" . esc_html( $i ) . "</option>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
if ( in_array( $display_on, array( 's_posts', 's_pages', 's_custom_posts', 's_tags',
|
||||
'latest_posts' ) ) ) {
|
||||
$nnr_hfcm_locations = array(
|
||||
'header' => __( 'Header', 'header-footer-code-manager' ),
|
||||
'before_content' => __( 'Before Content', 'header-footer-code-manager' ),
|
||||
'after_content' => __( 'After Content', 'header-footer-code-manager' ),
|
||||
'footer' => __( 'Footer', 'header-footer-code-manager' )
|
||||
);
|
||||
} else {
|
||||
$nnr_hfcm_locations = array(
|
||||
'header' => __( 'Header', 'header-footer-code-manager' ),
|
||||
'footer' => __( 'Footer', 'header-footer-code-manager' )
|
||||
);
|
||||
}
|
||||
?>
|
||||
<tr id="locationtr" style="<?php echo esc_attr( $nnr_hfcm_location_style ); ?>">
|
||||
<th class="hfcm-th-width">
|
||||
<?php esc_html_e( 'Location', 'header-footer-code-manager' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<select name="data[location]" id="data_location">
|
||||
<?php
|
||||
foreach ( $nnr_hfcm_locations as $lkey => $statusv ) {
|
||||
if ( $location === $lkey ) {
|
||||
echo "<option value='" . esc_attr( $lkey ) . "' selected='selected'>" . esc_html( $statusv ) . '</option>';
|
||||
} else {
|
||||
echo "<option value='" . esc_attr( $lkey ) . "'>" . esc_html( $statusv ) . '</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<p>
|
||||
<b><?php _e( "Note", 'header-footer-code-manager' ); ?></b>: <?php _e( "Not all locations (such as before content) exist on all page/post types. The location will only appear as an option if the appropriate hook exists on the page.", 'header-footer-code-manager' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php $nnr_hfcm_device_type_array = array(
|
||||
'both' => __( 'Show on All Devices', 'header-footer-code-manager' ),
|
||||
'desktop' => __( 'Only Desktop', 'header-footer-code-manager' ),
|
||||
'mobile' => __( 'Only Mobile Devices', 'header-footer-code-manager' )
|
||||
) ?>
|
||||
<?php $nnr_hfcm_status_array = array(
|
||||
'active' => __( 'Active', 'header-footer-code-manager' ),
|
||||
'inactive' => __( 'Inactive', 'header-footer-code-manager' )
|
||||
) ?>
|
||||
<tr>
|
||||
<th class="hfcm-th-width"><?php esc_html_e( 'Device Display', 'header-footer-code-manager' ); ?></th>
|
||||
<td>
|
||||
<select name="data[device_type]">
|
||||
<?php
|
||||
foreach ( $nnr_hfcm_device_type_array as $smkey => $typev ) {
|
||||
if ( $device_type === $smkey ) {
|
||||
echo "<option value='" . esc_attr( $smkey ) . "' selected='selected'>" . esc_html( $typev ) . '</option>';
|
||||
} else {
|
||||
echo "<option value='" . esc_attr( $smkey ) . "'>" . esc_html( $typev ) . '</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="hfcm-th-width"><?php esc_html_e( 'Status', 'header-footer-code-manager' ); ?></th>
|
||||
<td>
|
||||
<select name="data[status]">
|
||||
<?php
|
||||
foreach ( $nnr_hfcm_status_array as $skey => $statusv ) {
|
||||
if ( $status === $skey ) {
|
||||
echo "<option value='" . esc_attr( $skey ) . "' selected='selected'>" . esc_html( $statusv ) . '</option>';
|
||||
} else {
|
||||
echo "<option value='" . esc_attr( $skey ) . "'>" . esc_html( $statusv ) . '</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php if ( $update ) : ?>
|
||||
<tr>
|
||||
<th class="hfcm-th-width"><?php esc_html_e( 'Shortcode', 'header-footer-code-manager' ); ?></th>
|
||||
<td>
|
||||
<p>
|
||||
[hfcm id="<?php echo esc_html( $id ); ?>"]
|
||||
<?php if ( $update ) :
|
||||
?>
|
||||
<a data-shortcode='[hfcm id="<?php echo absint( $id ); ?>"]'
|
||||
href="javascript:void(0);" class="nnr-btn-click-to-copy nnr-btn-copy-inline"
|
||||
id="hfcm_copy_shortcode">
|
||||
<?php esc_html_e( 'Copy', 'header-footer-code-manager' ); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="hfcm-th-width">
|
||||
<?php esc_html_e( 'Changelog', 'header-footer-code-manager' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<p>
|
||||
<?php esc_html_e( 'Snippet created by', 'header-footer-code-manager' ); ?>
|
||||
<b><?php echo esc_html( $createdby ); ?></b> <?php echo _e( 'on', 'header-footer-code-manager' ) . ' ' . date_i18n( get_option( 'date_format' ), strtotime( $createdon ) ) . ' ' . __( 'at', 'header-footer-code-manager' ) . ' ' . date_i18n( get_option( 'time_format' ), strtotime( $createdon ) ) ?>
|
||||
<br/>
|
||||
<?php if ( !empty( $lastmodifiedby ) ) : ?>
|
||||
<?php esc_html_e( 'Last edited by', 'header-footer-code-manager' ); ?>
|
||||
<b><?php echo esc_html( $lastmodifiedby ); ?></b> <?php echo _e( 'on', 'header-footer-code-manager' ) . ' ' . date_i18n( get_option( 'date_format' ), strtotime( $lastrevisiondate ) ) . ' ' . __( 'at', 'header-footer-code-manager' ) . ' ' . date_i18n( get_option( 'time_format' ), strtotime( $lastrevisiondate ) ) ?>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
<div class="nnr-mt-20">
|
||||
<h1><?php esc_html_e( 'Snippet', 'header-footer-code-manager' ); ?>
|
||||
/ <?php esc_html_e( 'Code', 'header-footer-code-manager' ) ?></h1>
|
||||
<div class="nnr-mt-20 nnr-hfcm-codeeditor-box">
|
||||
<textarea name="data[snippet]" aria-describedby="nnr-newcontent-description" id="nnr_newcontent"
|
||||
rows="20"><?php echo html_entity_decode( $snippet ); ?></textarea>
|
||||
|
||||
<p class="notice notice-warning nnr-padding10" id="nnr-snippet-warning">
|
||||
<?php _e( 'Warning: Using improper code or untrusted sources code can break your site or create security risks. <a href="https://draftpress.com/security-risks-of-wp-plugins-that-allow-code-editing-or-insertion" target="_blank">Learn more</a>.', 'header-footer-code-manager' ); ?>
|
||||
</p>
|
||||
<div class="wp-core-ui">
|
||||
<input type="submit"
|
||||
name="<?php echo $update ? 'update' : 'insert'; ?>"
|
||||
value="<?php echo $update ? esc_html__( 'Update', 'header-footer-code-manager' ) : esc_html__( 'Save', 'header-footer-code-manager' ) ?>"
|
||||
class="button button-primary button-large nnr-btnsave">
|
||||
<?php if ( $update ) :
|
||||
$delete_nonce = wp_create_nonce( 'hfcm_delete_snippet' );
|
||||
?>
|
||||
<a onclick="return nnr_confirm_delete_snippet();"
|
||||
href="<?php echo esc_url( admin_url( 'admin.php?page=hfcm-list&action=delete&_wpnonce=' . $delete_nonce . '&snippet=' . absint( $id ) ) ); ?>"
|
||||
class="button button-secondary button-large nnr-btndelete"><?php esc_html_e( 'Delete', 'header-footer-code-manager' ); ?></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if (defined( 'DISALLOW_FILE_EDIT' ) && true === DISALLOW_FILE_EDIT && !get_user_meta(get_current_user_id(),'hfcm_file_edit_plugin_notice_dismissed', true) ) {
|
||||
?>
|
||||
<div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js">
|
||||
<div class="notification-dialog-background"></div>
|
||||
<div class="notification-dialog">
|
||||
<div class="file-editor-warning-content">
|
||||
<div class="file-editor-warning-message">
|
||||
<h1>Heads up!</h1>
|
||||
<p>
|
||||
<?php _e('Your site has <a href="https://draftpress.com/disallow-file-edit-setting-wordpress" target="_blank">disallow_file_edit</a> setting enabled inside the wp-config file to prevent file edits. By using this plugin, you acknowledge that you know what you’re doing and intend on adding code snippets only from trusted sources.', 'header-footer-code-manager'); ?>
|
||||
</p>
|
||||
</div>
|
||||
<p>
|
||||
<?php
|
||||
if ( $update ) :
|
||||
$hfcm_file_edit_dismiss_action = admin_url( 'admin.php?page=hfcm-update&hfcm-file-edit-notice-dismissed=1&id=' . absint( $id ) );
|
||||
else :
|
||||
$hfcm_file_edit_dismiss_action = admin_url( 'admin.php?page=hfcm-create&hfcm-file-edit-notice-dismissed=1' );
|
||||
endif;
|
||||
?>
|
||||
<a href="<?php echo $hfcm_file_edit_dismiss_action; ?>" class="file-editor-warning-dismiss button button-primary" id="nnr-dismiss-editor-warning">I understand</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
// Register the script
|
||||
wp_register_script('hfcm_showboxes', plugins_url('js/nnr-hfcm-showboxes.js', dirname(__FILE__)), array( 'jquery' ));
|
||||
|
||||
|
||||
// Localize the script with new data
|
||||
$translation_array = array(
|
||||
'header' => __('Header', 'header-footer-code-manager'),
|
||||
'before_content' => __('Before Content', 'header-footer-code-manager'),
|
||||
'after_content' => __('After Content', 'header-footer-code-manager'),
|
||||
'footer' => __('Footer', 'header-footer-code-manager'),
|
||||
'security' => wp_create_nonce('hfcm-get-posts'),
|
||||
);
|
||||
wp_localize_script('hfcm_showboxes', 'hfcm_localize', $translation_array);
|
||||
|
||||
// Enqueued script with localized data.
|
||||
wp_enqueue_script('hfcm_showboxes');
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1>
|
||||
<?php _e('Tools', 'header-footer-code-manager'); ?>
|
||||
</h1>
|
||||
<div class="hfcm-meta-box-wrap hfcm-grid">
|
||||
<div id="normal-sortables" class="meta-box-sortables">
|
||||
<div id="hfcm-admin-tool-export" class="postbox ">
|
||||
<div class="postbox-header">
|
||||
<h2 class="hndle">
|
||||
<?php _e('Export Snippets', 'header-footer-code-manager'); ?>
|
||||
</h2>
|
||||
</div>
|
||||
<div class="inside">
|
||||
<form method="post">
|
||||
<p>
|
||||
<?php _e(
|
||||
'Select the snippets you would like to export and then select your export method. Use the
|
||||
download button to export to a .json file which you can then import to another HFCM
|
||||
installation', 'header-footer-code-manager'
|
||||
); ?>.
|
||||
</p>
|
||||
<div class="hfcm-notice notice-warning">
|
||||
<p><?php _e('NOTE: Import/Export Functionality is only intended to operate within the same website. Using the export/import to move snippets from one website to a different site, may result in inconsistent behavior, particularly if you have specific elements as criteria such as pages, posts, categories, or tags.', 'header-footer-code-manager'); ?></p>
|
||||
</div>
|
||||
<div class="hfcm-fields">
|
||||
<div class="hfcm-field hfcm-field-checkbox" data-name="keys" data-type="checkbox">
|
||||
<div class="hfcm-label">
|
||||
<label for="keys">
|
||||
<?php _e('Select Snippets', 'header-footer-code-manager'); ?>
|
||||
</label>
|
||||
</div>
|
||||
<div class="hfcm-input">
|
||||
<input type="hidden" name="keys">
|
||||
<ul class="hfcm-checkbox-list hfcm-bl">
|
||||
<?php if (!empty($nnr_hfcm_snippets) ) {
|
||||
foreach ( $nnr_hfcm_snippets as $nnr_key => $nnr_hfcm_snippet ) {
|
||||
?>
|
||||
<li>
|
||||
<label>
|
||||
<input type="checkbox"
|
||||
id="keys-snippet_<?php echo absint($nnr_hfcm_snippet->script_id); ?>"
|
||||
name="nnr_hfcm_snippets[]"
|
||||
value="snippet_<?php echo absint($nnr_hfcm_snippet->script_id); ?>"> <?php echo esc_html($nnr_hfcm_snippet->name); ?>
|
||||
</label>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
} ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="hfcm-submit">
|
||||
<button type="submit" name="action" class="button button-primary" value="download">
|
||||
<?php _e('Export File', 'header-footer-code-manager'); ?>
|
||||
</button>
|
||||
</p>
|
||||
<?php wp_nonce_field('hfcm-nonce'); ?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div id="hfcm-admin-tool-import" class="postbox ">
|
||||
<div class="postbox-header">
|
||||
<h2 class="hndle">
|
||||
<?php _e('Import Snippets', 'header-footer-code-manager'); ?>
|
||||
</h2>
|
||||
</div>
|
||||
<div class="inside">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<p>
|
||||
<?php _e(
|
||||
'Select the HFCM JSON file you would like to import. When you click the import button below,
|
||||
HFCM will import the field groups.', 'header-footer-code-manager'
|
||||
); ?>
|
||||
</p>
|
||||
<div class="hfcm-fields">
|
||||
<div class="hfcm-field hfcm-field-file" data-name="hfcm_import_file" data-type="file">
|
||||
<div class="hfcm-label">
|
||||
<label for="hfcm_import_file">
|
||||
<?php _e('Select File', 'header-footer-code-manager'); ?>
|
||||
</label>
|
||||
</div>
|
||||
<div class="hfcm-input">
|
||||
<div class="hfcm-file-uploader" data-library="all" data-mime_types=""
|
||||
data-uploader="basic">
|
||||
<div class="hide-if-value">
|
||||
<label class="hfcm-basic-uploader">
|
||||
<input type="file" name="nnr_hfcm_import_file"
|
||||
id="nnr_hfcm_import_file">
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="hfcm-submit">
|
||||
<input type="submit" class="button button-primary" value="<?php echo __('Import', 'header-footer-code-manager');?>">
|
||||
</p>
|
||||
<?php wp_nonce_field('hfcm-nonce'); ?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user