Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/class-ad-code-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ class Ad_Code_Manager {

public $ad_codes = array();
public $whitelisted_conditionals = array();
public $title = 'Ad Code Manager';
public $post_type = 'acm-code';
public $plugin_slug = 'ad-code-manager';
public $manage_ads_cap = 'manage_options';
public $post_type_labels;
public $logical_operator;
public $ad_tag_ids;
public $providers;
Expand Down Expand Up @@ -129,13 +127,6 @@ function action_load_providers() {
* @since 0.1
*/
function action_init() {
load_plugin_textdomain( 'ad-code-manager', false, plugin_basename( dirname( __FILE__ ) ) . '/languages/' );

$this->post_type_labels = array(
'name' => __( 'Ad Codes', 'ad-code-manager' ),
'singular_name' => __( 'Ad Code', 'ad-code-manager' ),
);

// Allow other conditionals to be used
$this->whitelisted_conditionals = array(
'is_home',
Expand Down Expand Up @@ -192,14 +183,17 @@ function action_init() {
* @since 0.1
*/
function register_acm_post_type() {
register_post_type(
$this->post_type,
array(
'labels' => $this->post_type_labels,
$labels = array(
'name' => _x( 'Ad Codes', 'Post Type General Name', 'ad-code-manager' ),
'singular_name' => _x( 'Ad Code', 'Post Type Singular Name', 'ad-code-manager' ),
);
$args = array(
'labels' => $labels,
'public' => false,
'rewrite' => false,
)
);

register_post_type( $this->post_type, $args );
}

/**
Expand Down Expand Up @@ -587,7 +581,13 @@ function edit_conditionals( $ad_code_id, $conditionals = array() ) {
* Hook in our submenu page to the navigation
*/
public function action_admin_menu() {
$hook = add_submenu_page( 'tools.php', $this->title, $this->title, $this->manage_ads_cap, $this->plugin_slug, array( $this, 'admin_view_controller' ) );
$hook = add_management_page(
__( 'Ad Code Manager', 'ad-code-manager' ),
__( 'Ad Code Manager', 'ad-code-manager' ),
$this->manage_ads_cap,
$this->plugin_slug,
array( $this, 'admin_view_controller' )
);
add_action( 'load-' . $hook, array( $this, 'action_load_ad_code_manager' ) );
}

Expand Down
32 changes: 14 additions & 18 deletions views/ad-code-manager.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/
?>
<div class="acm-ui-wrapper wrap">
<h2>Ad Code Manager</h2>
<?php
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<?php
if ( isset( $_REQUEST['message'] ) ) {
switch ( $_REQUEST['message'] ) {
case 'ad-code-added':
Expand All @@ -24,12 +24,12 @@
$message_text = '';
break;
}
if ( $message_text ) {
if ( '' !== $message_text ) {
echo '<div class="message updated"><p>' . esc_html( $message_text ) . '</p></div>';
}
}
}
?>
<p> Refer to help section for more information</p>
<p><?php esc_html_e( 'Refer to help section for more information.', 'ad-code-manager' ); ?></p>
</div>

<div class="wrap nosubsub">
Expand All @@ -55,23 +55,19 @@
<div class="form-wrap">
<?php
// Only show the provider selector if one hasn't been specified at the code level.
if ( ! apply_filters( 'acm_provider_slug', false ) ) :
if ( ! apply_filters( 'acm_provider_slug', false ) ) :
?>
<div class="acm-global-options">
<h3><?php _e( 'Configuration', 'ad-code-manager' ); ?></h3>
<h2><?php esc_html_e( 'Configuration', 'ad-code-manager' ); ?></h2>
<div class="form-wrap">
<form action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post" name="updatesettings" id="updatesettings">
<div id="provider-field" class="form-field form-required">
<label for="provider"><?php _e( 'Select a provider:', 'ad-code-manager' ); ?></label>
<label for="provider"><?php esc_html_e( 'Select a provider:', 'ad-code-manager' ); ?></label>
<select name="provider" id="provider">
<?php
<?php
$current_provider = $this->get_option( 'provider' );
foreach ( $this->providers as $slug => $provider ) :
if ( isset( $provider['label'] ) ) {
$label = $provider['label'];
} else {
$label = ucwords( str_replace( '_', ' ', $slug ) );
}
$label = $provider['label'] ?? ucwords( str_replace( '_', ' ', $slug ) );
?>
<option value="<?php echo esc_attr( $slug ); ?>" <?php selected( $slug, $current_provider ); ?>><?php echo esc_html( $label ); ?></option>
<?php endforeach; ?>
Expand All @@ -86,7 +82,7 @@
</div>
</div>
<?php endif; ?>
<h3><?php _e( 'Add New Ad Code', 'ad-code-manager' ); ?></h3>
<h2><?php esc_html_e( 'Add New Ad Code', 'ad-code-manager' ); ?></h2>
<form id="add-adcode" method="POST" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" class="validate">
<input type="hidden" name="action" value="acm_admin_action" />
<input type="hidden" name="method" value="add" />
Expand Down Expand Up @@ -129,11 +125,11 @@
?>
<div class="form-field acm-conditional-fields" id="conditional-tpl">
<div class="form-new-row">
<label for="acm-conditionals"><?php _e( 'Conditionals', 'ad-code-manager' ); ?></label>
<label for="acm-conditionals"><?php esc_html_e( 'Conditionals', 'ad-code-manager' ); ?></label>
<div class="conditional-single-field" id="conditional-single-field-master">
<div class="conditional-function">
<select name="acm-conditionals[]">
<option value=""><?php _e( 'Select conditional', 'ad-code-manager' ); ?></option>
<option value=""><?php esc_html_e( 'Select conditional', 'ad-code-manager' ); ?></option>
<?php
foreach ( $this->whitelisted_conditionals as $key ) :
?>
Expand All @@ -147,7 +143,7 @@
</div>
</div>
<div class="form-field form-add-more">
<a href="#" class="button button-secondary add-more-conditionals">Add more</a>
<a href="#" class="button button-secondary add-more-conditionals"><?php esc_html_e( 'Add more', 'ad-code-manager' ); ?></a>
</div>
</div>
<p class="clear"></p>
Expand Down