*/
class Advertisement_Space_Admin {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Advertisement_Space_Loader as all of the hooks are defined
* in that particular class.
*
* The Advertisement_Space_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/advertisement-space-admin.css', array(), $this->version, 'all' );
}
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Advertisement_Space_Loader as all of the hooks are defined
* in that particular class.
*
* The Advertisement_Space_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/advertisement-space-admin.js', array( 'jquery' ), $this->version, false );
}
// Register Custom Post Type
function advertisement_space() {
$args = [
'label' => esc_html__( 'Advertisements', 'text-domain' ),
'labels' => [
'menu_name' => esc_html__( 'Advertisements', 'your-textdomain' ),
'name_admin_bar' => esc_html__( 'Advertisement', 'your-textdomain' ),
'add_new' => esc_html__( 'Add Advertisement', 'your-textdomain' ),
'add_new_item' => esc_html__( 'Add new Advertisement', 'your-textdomain' ),
'new_item' => esc_html__( 'New Advertisement', 'your-textdomain' ),
'edit_item' => esc_html__( 'Edit Advertisement', 'your-textdomain' ),
'view_item' => esc_html__( 'View Advertisement', 'your-textdomain' ),
'update_item' => esc_html__( 'View Advertisement', 'your-textdomain' ),
'all_items' => esc_html__( 'All Advertisements', 'your-textdomain' ),
'search_items' => esc_html__( 'Search Advertisements', 'your-textdomain' ),
'parent_item_colon' => esc_html__( 'Parent Advertisement', 'your-textdomain' ),
'not_found' => esc_html__( 'No Advertisements found', 'your-textdomain' ),
'not_found_in_trash' => esc_html__( 'No Advertisements found in Trash', 'your-textdomain' ),
'name' => esc_html__( 'Advertisements', 'your-textdomain' ),
'singular_name' => esc_html__( 'Advertisement', 'your-textdomain' ),
],
'public' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'show_in_rest' => false,
'capability_type' => 'post',
'hierarchical' => true,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite_no_front' => false,
'show_in_menu' => true,
'menu_icon' => 'dashicons-analytics',
'supports' => [
'title',
'thumbnail',
'custom-fields',
],
'rewrite' => true
];
register_post_type( 'advertisement', $args );
}
private $screens = array(
'advertisement',
);
private $fields = array(
array(
'id' => 'advertisement-img',
'label' => 'Advertisement',
'type' => 'media',
),
array(
'id' => 'advertisements-url',
'label' => 'Advertisements Url',
'type' => 'url',
),
array(
'id' => 'enable-advertisement',
'label' => 'Enable Advertisement',
'type' => 'checkbox',
),
array(
'id' => 'start-date',
'label' => 'Start Date',
'type' => 'date',
),
array(
'id' => 'end-date',
'label' => 'End Date',
'type' => 'date',
),
);
/**
* Hooks into WordPress' add_meta_boxes function.
* Goes through screens (post types) and adds the meta box.
*/
public function add_meta_boxes() {
foreach ( $this->screens as $screen ) {
add_meta_box(
'advertisement',
__( 'Advertisement', 'text-domain' ),
array( $this, 'add_meta_box_callback' ),
$screen,
'normal',
'default'
);
}
}
/**
* Generates the HTML for the meta box
*
* @param object $post WordPress post object
*/
public function add_meta_box_callback( $post ) {
wp_nonce_field( 'advertisement_data', 'advertisement_nonce' );
$this->generate_fields( $post );
}
/**
* Hooks into WordPress' admin_footer function.
* Adds scripts for media uploader.
*/
public function admin_footer() {
?>fields as $field ) {
$label = '';
$db_value = get_post_meta( $post->ID, 'advertisement_' . $field['id'], true );
switch ( $field['type'] ) {
case 'checkbox':
$input = sprintf(
'',
$db_value === '1' ? 'checked' : '',
$field['id'],
$field['id']
);
break;
case 'media':
$input = '';
$input .= sprintf(
' ',
$field['id'],
$field['id'],
$db_value,
$field['id'],
$field['id']
);
break;
default:
$input = sprintf(
'',
$field['type'] !== 'color' ? 'class="regular-text"' : '',
$field['id'],
$field['id'],
$field['type'],
$db_value
);
}
$output .= $this->row_format( $label, $input );
}
echo '
| Total Clicks: | |
|---|---|
| Total View |
advertisment_get_meta( 'advertisment_advertisement_type' ) === 'popup' ) ? 'checked' : ''; ?>>
advertisment_get_meta( 'advertisment_advertisement_type' ) === 'header_large' ) ? 'checked' : ''; ?>>
advertisment_get_meta( 'advertisment_advertisement_type' ) === 'header_small' ) ? 'checked' : ''; ?>>