Skip to content

Commit

Permalink
WordPress Plugin Directory review
Browse files Browse the repository at this point in the history
  • Loading branch information
rafasashi committed Mar 11, 2023
1 parent 81cbbe1 commit e917a7d
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 131 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# woo-book-chapter-tab
Extends WooCommerce to allow you to display the Chapters and Sections of a book, ebook or documentation in a new tab on the single product page.
Extends WC to allow you to display the Chapters and Sections of a book, ebook or documentation in a new tab on the single product page.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

if ( ! defined( 'ABSPATH' ) ) exit;

class WooCommerce_Book_Chapter_Tab_Settings {
class ECommerce_Book_Chapter_Tab_Settings {

/**
* The single instance of WooCommerce_Book_Chapter_Tab_Settings.
* The single instance of ECommerce_Book_Chapter_Tab_Settings.
* @var object
* @access private
* @since 1.0.0
Expand Down Expand Up @@ -53,7 +53,7 @@ public function __construct ( $parent ) {
add_action( 'admin_menu' , array( $this, 'add_menu_items' ) );

// Add settings link to plugins page
add_filter( 'plugin_action_links_' . plugin_basename( $this->parent->file ) , array( $this, 'add_settings_link' ) );
add_filter( 'plugin_action_links', array($this,'add_settings_link'),10,2);
}

/**
Expand Down Expand Up @@ -84,7 +84,7 @@ public function add_setting_page() {
add_menu_page( 'rew_plugin_panel', 'Code Market', 'nosuchcapability', 'rew_plugin_panel', NULL, $logo, $position );
}

add_submenu_page( 'rew_plugin_panel', 'Book Chapter Tab', 'Book Chapter Tab', 'manage_options', 'woocommerce-book-chapter-tab', array( $this, 'settings_page' ) );
add_submenu_page( 'rew_plugin_panel', 'Book Chapter Tab', 'Book Chapter Tab', 'manage_options', 'ecommerce-book-chapter-tab', array( $this, 'settings_page' ) );
remove_submenu_page( 'rew_plugin_panel', 'rew_plugin_panel' );
}

Expand Down Expand Up @@ -123,11 +123,16 @@ public function settings_assets () {
* @param array $links Existing links
* @return array Modified links
*/
public function add_settings_link ( $links ) {
public function add_settings_link( $links, $file ) {

$settings_link = '<a href="admin.php?page=' . $this->parent->_token . '">' . __( 'Settings', 'woocommerce-book-chapter-tab' ) . '</a>';
array_push( $links, $settings_link );
return $links;
if( strpos( $file, basename( $this->parent->file ) ) !== false ) {

$settings_link = '<a href="' . get_admin_url(null,'admin.php?page=wc-settings&tab=products&section=rew-tabs') . '">' . __( 'Settings', 'ecommerce-book-chapter-tab' ) . '</a>';

array_push( $links, $settings_link );
}

return $links;
}

/**
Expand All @@ -151,13 +156,13 @@ public function register_settings () {
$current_section = '';
if ( isset( $_POST['tab'] ) && $_POST['tab'] ) {

$current_section = $_POST['tab'];
$current_section = sanitize_text_field($_POST['tab']);
}
else {

if ( isset( $_GET['tab'] ) && $_GET['tab'] ) {

$current_section = $_GET['tab'];
$current_section = sanitize_text_field($_GET['tab']);
}
}

Expand Down Expand Up @@ -193,7 +198,7 @@ public function register_settings () {
public function settings_section ( $section ) {

$html = '<p> ' . $this->settings[ $section['id'] ]['description'] . '</p>' . "\n";
echo $html;
echo wp_kses_normalize_entities($html);
}

/**
Expand All @@ -207,7 +212,7 @@ public function settings_page () {
// Build page HTML
$html = '<div class="wrap" id="' . $this->parent->_token . '_settings">' . "\n";

$html .= '<h2>' . __( $plugin_data['Name'] , 'woocommerce-book-chapter-tab' ) . '</h2>' . "\n";
$html .= '<h2>' . __( $plugin_data['Name'] , 'ecommerce-book-chapter-tab' ) . '</h2>' . "\n";

$tab = '';
if ( isset( $_GET['tab'] ) && $_GET['tab'] ) {
Expand Down Expand Up @@ -264,18 +269,18 @@ public function settings_page () {

$html .= '</div>';

echo $html;
echo wp_kses_normalize_entities($html);
}

/**
* Main WooCommerce_Book_Chapter_Tab_Settings Instance
* Main ECommerce_Book_Chapter_Tab_Settings Instance
*
* Ensures only one instance of WooCommerce_Book_Chapter_Tab_Settings is loaded or can be loaded.
* Ensures only one instance of ECommerce_Book_Chapter_Tab_Settings is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @see WooCommerce_Book_Chapter_Tab()
* @return Main WooCommerce_Book_Chapter_Tab_Settings instance
* @see ECommerce_Book_Chapter_Tab()
* @return Main ECommerce_Book_Chapter_Tab_Settings instance
*/
public static function instance ( $parent ) {
if ( is_null( self::$_instance ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

if ( ! defined( 'ABSPATH' ) ) exit;

class WooCommerce_Book_Chapter_Tab {
class ECommerce_Book_Chapter_Tab {

/**
* The single instance of WooCommerce_Book_Chapter_Tab.
* The single instance of ECommerce_Book_Chapter_Tab.
* @var object
* @access private
* @since 1.0.0
Expand Down Expand Up @@ -107,7 +107,7 @@ public function __construct ( $file = '', $version = '1.0.0' ) {


$this->_version = $version;
$this->_token = 'woocommerce-book-chapter-tab';
$this->_token = 'ecommerce-book-chapter-tab';
$this->_base = 'wbch_';

$this->premium_url = 'https://code.recuweb.com/download/woocommerce-book-chapter-tab/';
Expand All @@ -117,14 +117,14 @@ public function __construct ( $file = '', $version = '1.0.0' ) {
$this->dir = dirname( $this->file );
$this->views = trailingslashit( $this->dir ) . 'views';
$this->assets_dir = trailingslashit( $this->dir ) . 'assets';
$this->assets_url = esc_url( trailingslashit( plugins_url( '/assets/', $this->file ) ) );
$this->assets_url = home_url( trailingslashit( str_replace( ABSPATH, '', $this->dir )) . 'assets/' );

$this->script_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';

WooCommerce_Book_Chapter_Tab::$plugin_prefix = $this->_base;
WooCommerce_Book_Chapter_Tab::$plugin_basefile = $this->file;
WooCommerce_Book_Chapter_Tab::$plugin_url = plugin_dir_url($this->file);
WooCommerce_Book_Chapter_Tab::$plugin_path = trailingslashit($this->dir);
ECommerce_Book_Chapter_Tab::$plugin_prefix = $this->_base;
ECommerce_Book_Chapter_Tab::$plugin_basefile = $this->file;
ECommerce_Book_Chapter_Tab::$plugin_url = plugin_dir_url($this->file);
ECommerce_Book_Chapter_Tab::$plugin_path = trailingslashit($this->dir);

// register plugin activation hook

Expand All @@ -140,11 +140,11 @@ public function __construct ( $file = '', $version = '1.0.0' ) {

// Load API for generic admin functions

$this->admin = new WooCommerce_Book_Chapter_Tab_Admin_API($this);
$this->admin = new ECommerce_Book_Chapter_Tab_Admin_API($this);

/* Localisation */

$locale = apply_filters('plugin_locale', get_locale(), 'woocommerce-book-chapter-tab');
$locale = apply_filters('plugin_locale', get_locale(), 'ecommerce-book-chapter-tab');
load_textdomain('wc_book_chapter', WP_PLUGIN_DIR . "/".plugin_basename(dirname(__FILE__)).'/lang/wc_book_chapter-'.$locale.'.mo');
load_plugin_textdomain('wc_book_chapter', false, dirname(plugin_basename(__FILE__)).'/lang/');

Expand Down Expand Up @@ -277,7 +277,7 @@ public function __construct ( $file = '', $version = '1.0.0' ) {
} // End __construct ()

/**
* Init WooCommerce Book Chapter Tab extension once we know WooCommerce is active
* Init Book Chapter Tab extension once we know ECommerce is active
*/
public function init(){

Expand Down Expand Up @@ -310,7 +310,7 @@ public function init(){
}
else{

$this->notices->add_error('WooCommerce Book Chapter Tab '.__('requires at least <a href="http://www.woothemes.com/woocommerce/" target="_blank">WooCommerce ' . $this->woo_version . '</a> in order to work. Please upgrade <a href="'.admin_url('plugin-install.php?tab=search&type=term&s=WooCommerce').'" target="_blank">WooCommerce</a> first.', 'wc_book_chapter'));
$this->notices->add_error('Book Chapter Tab '.__('requires at least <a href="http://www.woothemes.com/woocommerce/" target="_blank">ECommerce ' . $this->woo_version . '</a> in order to work. Please upgrade <a href="'.admin_url('plugin-install.php?tab=search&type=term&s=ECommerce').'" target="_blank">ECommerce</a> first.', 'wc_book_chapter'));
}
}

Expand Down Expand Up @@ -459,7 +459,7 @@ public function add_support_link($links, $file){
return $links;
}

if($file == WooCommerce_Book_Chapter_Tab::$plugin_basefile){
if($file == ECommerce_Book_Chapter_Tab::$plugin_basefile){

$links[] = '<a href="https://code.recuweb.com" target="_blank">'.__('Docs', 'wc_book_chapter').'</a>';
}
Expand Down Expand Up @@ -510,7 +510,7 @@ public function get_product_book_chapters($product_id){

/**
* Write the images tab on the product view page for WC 2.0+.
* In WooCommerce these are handled by templates.
* In ECommerce these are handled by templates.
*/
public function chapters($tabs){

Expand All @@ -524,7 +524,7 @@ public function chapters($tabs){

$tabs['chapters'] = array(

'title' => __($this->title, 'woocommerce-book-chapter-tab').' ('.$countItems.')',
'title' => __($this->title, 'ecommerce-book-chapter-tab').' ('.$countItems.')',
'priority' => $this->priority,
'callback' => array($this, 'book_chapters_panel')
);
Expand All @@ -535,7 +535,7 @@ public function chapters($tabs){

/**
* Write the images tab panel on the product view page.
* In WooCommerce these are handled by templates.
* In ECommerce these are handled by templates.
*/
public function book_chapters_panel(){

Expand Down Expand Up @@ -589,7 +589,7 @@ public function book_chapters_panel(){

echo '<li class="wbch-section"'.( $this->showDots == 'yes' ? ' style="background: url(' . $this->assets_url . 'images/dot.png) center center repeat-x;"' : '' ) . '>';

echo '<span style="float:left;padding-right:5px;">' . $section . '</span>';
echo '<span style="padding-right:5px;">' . $section . '</span>';

echo '</li>';
}
Expand All @@ -616,7 +616,7 @@ public function register_post_type ( $post_type = '', $plural = '', $single = ''

if ( ! $post_type || ! $plural || ! $single ) return;

$post_type = new WooCommerce_Book_Chapter_Tab_Post_Type( $post_type, $plural, $single, $description, $options );
$post_type = new ECommerce_Book_Chapter_Tab_Post_Type( $post_type, $plural, $single, $description, $options );

return $post_type;
}
Expand All @@ -633,7 +633,7 @@ public function register_taxonomy ( $taxonomy = '', $plural = '', $single = '',

if ( ! $taxonomy || ! $plural || ! $single ) return;

$taxonomy = new WooCommerce_Book_Chapter_Tab_Taxonomy( $taxonomy, $plural, $single, $post_types, $taxonomy_args );
$taxonomy = new ECommerce_Book_Chapter_Tab_Taxonomy( $taxonomy, $plural, $single, $post_types, $taxonomy_args );

return $taxonomy;
}
Expand All @@ -646,9 +646,12 @@ public function register_taxonomy ( $taxonomy = '', $plural = '', $single = '',
*/
public function enqueue_styles () {

wp_register_style( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'css/frontend-1.0.1.css', array(), $this->_version );
wp_enqueue_style( $this->_token . '-frontend' );

if( is_product() ){

wp_register_style( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'css/frontend-1.0.1.css', array(), $this->_version );
wp_enqueue_style( $this->_token . '-frontend' );
}

} // End enqueue_styles ()

/**
Expand All @@ -659,13 +662,16 @@ public function enqueue_styles () {
*/
public function enqueue_scripts () {

if( $this->accordion == 'yes' ){

wp_register_script( $this->_token . '-jquery-accordion', esc_url( $this->assets_url ) . 'js/jquery.accordion.js', array( 'jquery' ), $this->_version );
wp_enqueue_script( $this->_token . '-jquery-accordion' );
if( is_product() ){

if( $this->accordion == 'yes' ){

wp_register_script( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'js/frontend.js', array( 'jquery' ), $this->_version );
wp_enqueue_script( $this->_token . '-frontend' );
wp_register_script( $this->_token . '-jquery-accordion', esc_url( $this->assets_url ) . 'js/jquery.accordion.js', array( 'jquery' ), $this->_version );
wp_enqueue_script( $this->_token . '-jquery-accordion' );

wp_register_script( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'js/frontend.js', array( 'jquery' ), $this->_version );
wp_enqueue_script( $this->_token . '-frontend' );
}
}

} // End enqueue_scripts ()
Expand All @@ -681,7 +687,7 @@ public function admin_enqueue_styles ( $hook = '' ) {
wp_register_style( $this->_token . '-admin', esc_url( $this->assets_url ) . 'css/admin.css', array(), $this->_version );
wp_enqueue_style( $this->_token . '-admin' );

if( isset($_GET['page']) && $_GET['page'] == 'woocommerce-book-chapter-tab' ){
if( isset($_GET['page']) && $_GET['page'] == 'ecommerce-book-chapter-tab' ){

wp_register_style( $this->_token . '-simpleLightbox', esc_url( $this->assets_url ) . 'css/simpleLightbox.min.css', array(), $this->_version );
wp_enqueue_style( $this->_token . '-simpleLightbox' );
Expand All @@ -700,7 +706,7 @@ public function admin_enqueue_scripts ( $hook = '' ) {
wp_register_script( $this->_token . '-admin', esc_url( $this->assets_url ) . 'js/admin.js', array( 'jquery' ), $this->_version );
wp_enqueue_script( $this->_token . '-admin' );

if( isset($_GET['page']) && $_GET['page'] == 'woocommerce-book-chapter-tab' ){
if( isset($_GET['page']) && $_GET['page'] == 'ecommerce-book-chapter-tab' ){

wp_register_script( $this->_token . '-simpleLightbox', esc_url( $this->assets_url ) . 'js/simpleLightbox.min.js', array( 'jquery' ), $this->_version );
wp_enqueue_script( $this->_token . '-simpleLightbox' );
Expand All @@ -718,7 +724,7 @@ public function admin_enqueue_scripts ( $hook = '' ) {
* @return void
*/
public function load_localisation () {
load_plugin_textdomain( 'woocommerce-book-chapter-tab', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
load_plugin_textdomain( 'ecommerce-book-chapter-tab', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
} // End load_localisation ()

/**
Expand All @@ -729,7 +735,7 @@ public function load_localisation () {
*/
public function load_plugin_textdomain () {

$domain = 'woocommerce-book-chapter-tab';
$domain = 'ecommerce-book-chapter-tab';

$locale = apply_filters( 'plugin_locale', get_locale(), $domain );

Expand All @@ -738,14 +744,14 @@ public function load_plugin_textdomain () {
} // End load_plugin_textdomain ()

/**
* Main WooCommerce_Book_Chapter_Tab Instance
* Main ECommerce_Book_Chapter_Tab Instance
*
* Ensures only one instance of WooCommerce_Book_Chapter_Tab is loaded or can be loaded.
* Ensures only one instance of ECommerce_Book_Chapter_Tab is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @see WooCommerce_Book_Chapter_Tab()
* @return Main WooCommerce_Book_Chapter_Tab instance
* @see ECommerce_Book_Chapter_Tab()
* @return Main ECommerce_Book_Chapter_Tab instance
*/
public static function instance ( $file = '', $version = '1.0.0' ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if ( ! defined( 'ABSPATH' ) ) exit;

class WooCommerce_Book_Chapter_Tab_Admin_API {
class ECommerce_Book_Chapter_Tab_Admin_API {

/**
* Constructor function
Expand Down Expand Up @@ -160,8 +160,8 @@ public function display_field ( $data = array(), $post = false, $echo = true ) {
$image_thumb = wp_get_attachment_thumb_url( $data );
}
$html .= '<img id="' . $option_name . '_preview" class="image_preview" src="' . $image_thumb . '" /><br/>' . "\n";
$html .= '<input id="' . $option_name . '_button" type="button" data-uploader_title="' . __( 'Upload an image' , 'woocommerce-book-chapter-tab' ) . '" data-uploader_button_text="' . __( 'Use image' , 'woocommerce-book-chapter-tab' ) . '" class="image_upload_button button" value="'. __( 'Upload new image' , 'woocommerce-book-chapter-tab' ) . '" />' . "\n";
$html .= '<input id="' . $option_name . '_delete" type="button" class="image_delete_button button" value="'. __( 'Remove image' , 'woocommerce-book-chapter-tab' ) . '" />' . "\n";
$html .= '<input id="' . $option_name . '_button" type="button" data-uploader_title="' . __( 'Upload an image' , 'ecommerce-book-chapter-tab' ) . '" data-uploader_button_text="' . __( 'Use image' , 'ecommerce-book-chapter-tab' ) . '" class="image_upload_button button" value="'. __( 'Upload new image' , 'ecommerce-book-chapter-tab' ) . '" />' . "\n";
$html .= '<input id="' . $option_name . '_delete" type="button" class="image_delete_button button" value="'. __( 'Remove image' , 'ecommerce-book-chapter-tab' ) . '" />' . "\n";
$html .= '<input id="' . $option_name . '" class="image_data_field" type="hidden" name="' . $option_name . '" value="' . $data . '"/><br/>' . "\n";
break;

Expand Down Expand Up @@ -291,10 +291,10 @@ public function display_field ( $data = array(), $post = false, $echo = true ) {
}

if ( ! $echo ) {
return $html;
return wp_kses_normalize_entities($html);
}

echo $html;
echo wp_kses_normalize_entities($html);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

if ( ! defined( 'ABSPATH' ) ) exit;

class WooCommerce_Book_Chapter_Tab_Admin_Notices {
class ECommerce_Book_Chapter_Tab_Admin_Notices {

/**
* The single instance of WooCommerce_Book_Chapter_Tab_Admin_Notices.
* The single instance of ECommerce_Book_Chapter_Tab_Admin_Notices.
* @var object
* @access private
* @since 1.0.0
Expand Down
Loading

0 comments on commit e917a7d

Please sign in to comment.