Plugin Directory

Changeset 2967544


Ignore:
Timestamp:
09/15/2023 02:37:05 PM (3 years ago)
Author:
jakeparis
Message:

Cleanup and reorganize.

  • move transient cache to lower-level function to catch more calls
  • improved block
  • better sanitization
Location:
bestseller-lists-from-new-york-times
Files:
26 added
9 deleted
4 edited
5 copied

Legend:

Unmodified
Added
Removed
  • bestseller-lists-from-new-york-times/tags/2.3.0/admin-page.php

    r2853610 r2967544  
    11<?php
    2 defined('ABSPATH') || die('Not allowed');
     2defined( 'ABSPATH' ) || die( 'Not allowed' );
    33
    44
    5 if( isset($_POST['nyt-bestseller-listings-settings']) ) :
     5if ( isset( $_POST['nyt-bestseller-listings-settings'] ) ) :
    66
    7     if( ! wp_verify_nonce( $_POST['_nyt-bestseller-listings-settings-nonce'], 'save-nyt-bestseller-settings' ) ) {
     7    if ( ! wp_verify_nonce( $_POST['_nyt-bestseller-listings-settings-nonce'], 'save-nyt-bestseller-settings' ) ) {
    88        echo '<div class="error updated"><p>Could not save. Perhaps the form timed out?</p></div>';
    99    } else {
    10         nytBestsellerListings::setApiKey( $_POST['nyt_bestseller_listings_apiKey']);
     10        NytBestsellerListings::setApiKey( sanitize_text_field( $_POST['nyt_bestseller_listings_apiKey'] ) );
    1111
    12         nytBestsellerListings::setCatalogLinkFormat($_POST['nyt_bestseller_listings_CatalogLinkFormat']);
     12        NytBestsellerListings::setCatalogLinkFormat( sanitize_text_field( $_POST['nyt_bestseller_listings_CatalogLinkFormat'] ) );
    1313    }
    1414
    1515endif;
    1616
    17 $apiKey = nytBestsellerListings::getApiKey();
    18 $catalogLinkFormat = nytBestsellerListings::getCatalogLinkFormat();
     17$api_key = NytBestsellerListings::getApiKey();
     18$catalog_link_format = NytBestsellerListings::getCatalogLinkFormat();
    1919?>
    2020<style>
     
    3737<h1>New York Times Bestseller Listings &mdash; Settings</h1>
    3838<form method="post" action="">
    39     <?php wp_nonce_field( 'save-nyt-bestseller-settings', '_nyt-bestseller-listings-settings-nonce' ) ?>
     39    <?php wp_nonce_field( 'save-nyt-bestseller-settings', '_nyt-bestseller-listings-settings-nonce' ); ?>
    4040
    4141    <label class="block">API Key</label>
    4242    <p class="help">You can get one of these <a href="https://developer.nytimes.com/signup">here.</a></p>
    43     <input type="text" class="wide" name="nyt_bestseller_listings_apiKey" value="<?= esc_attr($apiKey) ?>">
     43    <input type="text" class="wide" name="nyt_bestseller_listings_apiKey" value="<?php echo esc_attr( $api_key ); ?>">
    4444
    4545
    4646    <label class="block">Catalog Links</label>
    4747    <p class="help">You can add links to your library catalog to each book. Enter the catalog url below, using various placeholders to insert book variables. For example, settings this to <b>http://example.com/?serial={isbn}</b> would insert the book's isbn after the <b>serial=</b> in the resulting url. Leave this blank to hide links to a catalog.</p>
    48     <input type="text" class="wide" value="<?= esc_attr($catalogLinkFormat) ?>" name="nyt_bestseller_listings_CatalogLinkFormat">
     48    <input type="text" class="wide" value="<?php echo esc_attr( $catalog_link_format ); ?>" name="nyt_bestseller_listings_CatalogLinkFormat">
    4949    <p class="help">Placeholders: <b>{isbn}</b>, <b>{title}</b>, <b>{author}</b></p>
    5050
    51     <p>
    52         <input type="submit" class="button-primary" value="Save" name="nyt-bestseller-listings-settings">
    53     </p>
     51    <?php submit_button( 'Save', 'primary', 'nyt-bestseller-listings-settings' ); ?>
     52
    5453</form>
  • bestseller-lists-from-new-york-times/tags/2.3.0/functions.php

    r2705840 r2967544  
    11<?php
    2 defined('ABSPATH') || die('Not allowed');
     2defined( 'ABSPATH' ) || die( 'Not allowed' );
    33
    44
    5 function nytBestsellerListings_mainDisplay ($atts, $content){
    6     wp_enqueue_script('nyt-bestseller-listings');
    7     wp_enqueue_style('nyt-bestseller-listings');
     5function NytBestsellerListings_mainDisplay ( $atts, $content ) {
     6    wp_enqueue_script( 'nyt-bestseller-listings' );
     7    wp_enqueue_style( 'nyt-bestseller-listings' );
    88
    9     if( isset($atts['initialList']) )
     9    if ( isset( $atts['initialList'] ) )
    1010        $atts['initial-list'] = $atts['initialList'];
    1111
    1212    $atts = shortcode_atts([
    13         'initial-list' => nytBestsellerListings::getDefaultList(),
     13        'initial-list' => NytBestsellerListings::getDefaultList(),
    1414        'displayImages' => '1',
    1515    ], $atts, 'nyt_bestseller_listings' );
    1616
    17     if( isset($_GET['nytlist']) )
    18         $atts['initial-list'] = $_GET['nytlist'];
     17    if ( isset( $_GET['nytlist'] ) )
     18        $atts['initial-list'] = sanitize_text_field( $_GET['nytlist'] );
    1919
    20     if ($atts['displayImages']==='1') {
    21         $displayImages = true;
    22         $displayImagesJs = "true";
     20    if ( $atts['displayImages'] === '1' ) {
     21        $display_images = true;
     22        $display_images_js = 'true';
    2323    } else {
    24         $displayImages = false;
    25         $displayImagesJs = "false";
     24        $display_images = false;
     25        $display_images_js = 'false';
    2626    }
    2727
    28     $js = <<<JS
     28    $js = '
    2929        bslnyt = window.bslnyt || {};
     30        bslnyt.displayImages = ' . esc_js( $display_images_js ) . ';
     31    ';
    3032
    31         bslnyt.displayImages = $displayImagesJs;
    32 JS;
    33     wp_add_inline_script('nyt-bestseller-listings', $js, 'before' );
     33    wp_add_inline_script( 'nyt-bestseller-listings', $js, 'before' );
    3434
    35     $dropdown = nytBestsellerListings::getListsDropdown( $atts['initial-list'] );
     35    $dropdown = NytBestsellerListings::getListsDropdown( $atts['initial-list'] );
    3636
    37     if( $dropdown ) :
    38         $out = $dropdown 
     37    if ( ! empty( $dropdown ) ) :
     38        $out = $dropdown
    3939            . '<div class="nyt-bestseller-listings-booklist">'
    40             . nytBestsellerListings::getBookList( $atts['initial-list'], false, $displayImages )
    41             . '</div>' 
     40            . NytBestsellerListings::getBookList( $atts['initial-list'], true, $display_images )
     41            . '</div>'
    4242            . $dropdown;
    4343    else :
     
    4646
    4747    return $out;
    48 
    4948}
  • bestseller-lists-from-new-york-times/tags/2.3.0/index.php

    r2955023 r2967544  
    44Plugin URI:  https://jakeparis.com/wordpress-plugins/
    55Description: Integrate bestseller lists from the New York Times into your own site with a user-friendly interface.
    6 Version:     2.2.0
    7 Requires PHP: 5.4
    8 Requires at least: 4.9
     6Version:     2.3.0
     7Requires PHP: 7.4
     8Requires at least: 5.4
    99Tested up to: 6.3.0
    1010Author:      Jake Paris
     
    1313License URI: https://opensource.org/licenses/GPL-3.0
    1414*/
     15defined( 'ABSPATH' ) || die( 'Not allowed' );
    1516
    16 define('BSLNYT_PLUGIN_VERSION', '2.2.0');
    17 define('BSLNYT_PLUGIN_PATH', plugin_dir_path(__FILE__) );
    18 define('BSLNYT_PLUGIN_URL', plugins_url('/', __FILE__) );
     17define( 'BSLNYT_PLUGIN_VERSION', '2.3.0' );
     18define( 'BSLNYT_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
     19define( 'BSLNYT_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
    1920
    20 if( function_exists('register_block_type') )
    21     require_once BSLNYT_PLUGIN_PATH . 'blocks/block-registration.php';
    2221
    23 require_once BSLNYT_PLUGIN_PATH . 'nytBestsellerListings.class.php';
     22require_once BSLNYT_PLUGIN_PATH . 'class-nytbestsellerlistings.php';
    2423require_once BSLNYT_PLUGIN_PATH . 'functions.php';
    2524
    26 require_once BSLNYT_PLUGIN_PATH . 'plugin_updates.php';
     25require_once BSLNYT_PLUGIN_PATH . 'plugin-updates.php';
    2726
    28 add_action('wp_enqueue_scripts',function(){
    29     wp_register_script( 'nyt-bestseller-listings', 
    30         BSLNYT_PLUGIN_URL . 'public-assets/build/nyt-bestseller-listings.js',
     27add_action('wp_enqueue_scripts', function () {
     28    wp_register_script( 'nyt-bestseller-listings',
     29        BSLNYT_PLUGIN_URL . 'build/ui/public.js',
    3130        array(
    32             'jquery'
    33         ), 
     31            'jquery',
     32        ),
    3433        BSLNYT_PLUGIN_VERSION
    3534    );
    36     wp_register_style ( 'nyt-bestseller-listings',
    37         BSLNYT_PLUGIN_URL . 'public-assets/build/nyt-bestseller-listings.css',
     35    wp_register_style( 'nyt-bestseller-listings',
     36        BSLNYT_PLUGIN_URL . 'build/ui/public.css',
    3837        array(),
    3938        BSLNYT_PLUGIN_VERSION
    4039    );
    4140
    42     if( ! empty($_SERVER['HTTPS']) )
    43         $js_args = array('ajaxurl' => admin_url( 'admin-ajax.php','https' ) );
    44     else
    45         $js_args = array('ajaxurl' => admin_url( 'admin-ajax.php','http' ) );
     41    if ( ! empty( $_SERVER['HTTPS'] ) ) {
     42        $js_args = array( 'ajaxurl' => admin_url( 'admin-ajax.php', 'https' ) );
     43    } else {
     44        $js_args = array( 'ajaxurl' => admin_url( 'admin-ajax.php', 'http' ) );
     45    }
    4646    wp_localize_script( 'nyt-bestseller-listings', 'nyt_bestseller_listings_settings', $js_args );
    4747});
    4848
    4949
    50 add_action('init',function(){
    51     add_shortcode( 'nyt-bestseller-listings', 'nytBestsellerListings_mainDisplay');
     50add_action('init', function () {
     51    add_shortcode( 'nyt-bestseller-listings', function ( $atts, $content ) {
     52        return wp_kses_post( NytBestsellerListings_mainDisplay( $atts, $content ) );
     53    });
     54
     55    register_block_type( BSLNYT_PLUGIN_PATH . 'build/lists/block.json' );
    5256});
    5357
    54 add_action('admin_menu',function(){
     58
     59add_action('admin_menu', function () {
    5560    add_options_page( 'NYT Bestseller Lists', 'NYT Bestseller Lists', 'activate_plugins', 'nyt-bestseller-lists', 'nytBestSellerListings_adminPage' );
    5661});
    5762
    58 function nytBestSellerListings_adminPage(){
     63function nytBestSellerListings_adminPage() {
    5964    require_once BSLNYT_PLUGIN_PATH . 'admin-page.php';
    6065}
    6166
    6267
    63 add_action('wp_ajax_nyt_bestseller_listings_getList', 'nytBestSellerListings_ajax_getList');
    64 add_action('wp_ajax_nopriv_nyt_bestseller_listings_getList', 'nytBestSellerListings_ajax_getList');
    65 function nytBestSellerListings_ajax_getList(){
    66     $list = $_REQUEST['listName'];
     68add_action( 'wp_ajax_nyt_bestseller_listings_getList', 'nytBestSellerListings_ajax_getList' );
     69add_action( 'wp_ajax_nopriv_nyt_bestseller_listings_getList', 'nytBestSellerListings_ajax_getList' );
     70function nytBestSellerListings_ajax_getList() {
     71    $list = sanitize_text_field( $_GET['listName'] );
    6772
    68     $displayImages = ( isset($_REQUEST['displayImages']) )
    69         ? (bool) $_REQUEST['displayImages']
     73    $display_images = ( isset( $_GET['displayImages'] ) )
     74        ? (bool) $_GET['displayImages']
    7075        : true;
    7176
    72     $html = nytBestsellerListings::getBookList( $list, false, $displayImages );
    73     echo $html;
     77    $html = NytBestsellerListings::getBookList( $list, true, $display_images );
     78    echo wp_kses_post( $html );
    7479    exit;
    7580}
    7681
     82add_action( 'wp_ajax_nyt_bestseller_listings_getAllLists', 'nytBestSellerListings_ajax_getAllLists' );
     83add_action( 'wp_ajax_nopriv_nyt_bestseller_listings_getAllLists', 'nytBestSellerListings_ajax_getAllLists' );
     84function nytBestSellerListings_ajax_getAllLists () {
     85    $all_lists = NytBestsellerListings::getResults( 'names.json' );
     86    $all_lists_configured = [];
     87    if ( ! empty( $all_lists ) ) {
     88        foreach ( $all_lists->results as $list ) {
     89            $all_lists_configured[] = [
     90                'label' => $list->display_name,
     91                'value' => $list->list_name_encoded,
     92            ];
     93        }
     94    }
     95    wp_send_json_success( $all_lists_configured );
     96}
    7797
    78 register_deactivation_hook(__FILE__, function(){
    79     delete_option('nyt_bestseller_listings_apiKey');
    80     delete_option('nyt_bestseller_listings_defaultList');
     98register_deactivation_hook(__FILE__, function () {
     99    delete_option( 'nyt_bestseller_listings_apiKey' );
     100    delete_option( 'nyt_bestseller_listings_defaultList' );
    81101});
  • bestseller-lists-from-new-york-times/tags/2.3.0/readme.txt

    r2955023 r2967544  
    33Donate link: https://jakeparis.com/
    44Tags: books, library, bestsellers, libraries, reading lists
    5 Requires at least: 4.9
     5Requires at least: 5.4
    66Tested up to: 6.3.0
    77Stable tag: 2.2.0
     
    4646
    4747== Changelog ==
     48
     49= 2.3.0 =
     50
     51Reorganization of plugin; housekeeping.
    4852
    4953= 2.2.0 =
  • bestseller-lists-from-new-york-times/trunk/admin-page.php

    r2853610 r2967544  
    11<?php
    2 defined('ABSPATH') || die('Not allowed');
     2defined( 'ABSPATH' ) || die( 'Not allowed' );
    33
    44
    5 if( isset($_POST['nyt-bestseller-listings-settings']) ) :
     5if ( isset( $_POST['nyt-bestseller-listings-settings'] ) ) :
    66
    7     if( ! wp_verify_nonce( $_POST['_nyt-bestseller-listings-settings-nonce'], 'save-nyt-bestseller-settings' ) ) {
     7    if ( ! wp_verify_nonce( $_POST['_nyt-bestseller-listings-settings-nonce'], 'save-nyt-bestseller-settings' ) ) {
    88        echo '<div class="error updated"><p>Could not save. Perhaps the form timed out?</p></div>';
    99    } else {
    10         nytBestsellerListings::setApiKey( $_POST['nyt_bestseller_listings_apiKey']);
     10        NytBestsellerListings::setApiKey( sanitize_text_field( $_POST['nyt_bestseller_listings_apiKey'] ) );
    1111
    12         nytBestsellerListings::setCatalogLinkFormat($_POST['nyt_bestseller_listings_CatalogLinkFormat']);
     12        NytBestsellerListings::setCatalogLinkFormat( sanitize_text_field( $_POST['nyt_bestseller_listings_CatalogLinkFormat'] ) );
    1313    }
    1414
    1515endif;
    1616
    17 $apiKey = nytBestsellerListings::getApiKey();
    18 $catalogLinkFormat = nytBestsellerListings::getCatalogLinkFormat();
     17$api_key = NytBestsellerListings::getApiKey();
     18$catalog_link_format = NytBestsellerListings::getCatalogLinkFormat();
    1919?>
    2020<style>
     
    3737<h1>New York Times Bestseller Listings &mdash; Settings</h1>
    3838<form method="post" action="">
    39     <?php wp_nonce_field( 'save-nyt-bestseller-settings', '_nyt-bestseller-listings-settings-nonce' ) ?>
     39    <?php wp_nonce_field( 'save-nyt-bestseller-settings', '_nyt-bestseller-listings-settings-nonce' ); ?>
    4040
    4141    <label class="block">API Key</label>
    4242    <p class="help">You can get one of these <a href="https://developer.nytimes.com/signup">here.</a></p>
    43     <input type="text" class="wide" name="nyt_bestseller_listings_apiKey" value="<?= esc_attr($apiKey) ?>">
     43    <input type="text" class="wide" name="nyt_bestseller_listings_apiKey" value="<?php echo esc_attr( $api_key ); ?>">
    4444
    4545
    4646    <label class="block">Catalog Links</label>
    4747    <p class="help">You can add links to your library catalog to each book. Enter the catalog url below, using various placeholders to insert book variables. For example, settings this to <b>http://example.com/?serial={isbn}</b> would insert the book's isbn after the <b>serial=</b> in the resulting url. Leave this blank to hide links to a catalog.</p>
    48     <input type="text" class="wide" value="<?= esc_attr($catalogLinkFormat) ?>" name="nyt_bestseller_listings_CatalogLinkFormat">
     48    <input type="text" class="wide" value="<?php echo esc_attr( $catalog_link_format ); ?>" name="nyt_bestseller_listings_CatalogLinkFormat">
    4949    <p class="help">Placeholders: <b>{isbn}</b>, <b>{title}</b>, <b>{author}</b></p>
    5050
    51     <p>
    52         <input type="submit" class="button-primary" value="Save" name="nyt-bestseller-listings-settings">
    53     </p>
     51    <?php submit_button( 'Save', 'primary', 'nyt-bestseller-listings-settings' ); ?>
     52
    5453</form>
  • bestseller-lists-from-new-york-times/trunk/functions.php

    r2705840 r2967544  
    11<?php
    2 defined('ABSPATH') || die('Not allowed');
     2defined( 'ABSPATH' ) || die( 'Not allowed' );
    33
    44
    5 function nytBestsellerListings_mainDisplay ($atts, $content){
    6     wp_enqueue_script('nyt-bestseller-listings');
    7     wp_enqueue_style('nyt-bestseller-listings');
     5function NytBestsellerListings_mainDisplay ( $atts, $content ) {
     6    wp_enqueue_script( 'nyt-bestseller-listings' );
     7    wp_enqueue_style( 'nyt-bestseller-listings' );
    88
    9     if( isset($atts['initialList']) )
     9    if ( isset( $atts['initialList'] ) )
    1010        $atts['initial-list'] = $atts['initialList'];
    1111
    1212    $atts = shortcode_atts([
    13         'initial-list' => nytBestsellerListings::getDefaultList(),
     13        'initial-list' => NytBestsellerListings::getDefaultList(),
    1414        'displayImages' => '1',
    1515    ], $atts, 'nyt_bestseller_listings' );
    1616
    17     if( isset($_GET['nytlist']) )
    18         $atts['initial-list'] = $_GET['nytlist'];
     17    if ( isset( $_GET['nytlist'] ) )
     18        $atts['initial-list'] = sanitize_text_field( $_GET['nytlist'] );
    1919
    20     if ($atts['displayImages']==='1') {
    21         $displayImages = true;
    22         $displayImagesJs = "true";
     20    if ( $atts['displayImages'] === '1' ) {
     21        $display_images = true;
     22        $display_images_js = 'true';
    2323    } else {
    24         $displayImages = false;
    25         $displayImagesJs = "false";
     24        $display_images = false;
     25        $display_images_js = 'false';
    2626    }
    2727
    28     $js = <<<JS
     28    $js = '
    2929        bslnyt = window.bslnyt || {};
     30        bslnyt.displayImages = ' . esc_js( $display_images_js ) . ';
     31    ';
    3032
    31         bslnyt.displayImages = $displayImagesJs;
    32 JS;
    33     wp_add_inline_script('nyt-bestseller-listings', $js, 'before' );
     33    wp_add_inline_script( 'nyt-bestseller-listings', $js, 'before' );
    3434
    35     $dropdown = nytBestsellerListings::getListsDropdown( $atts['initial-list'] );
     35    $dropdown = NytBestsellerListings::getListsDropdown( $atts['initial-list'] );
    3636
    37     if( $dropdown ) :
    38         $out = $dropdown 
     37    if ( ! empty( $dropdown ) ) :
     38        $out = $dropdown
    3939            . '<div class="nyt-bestseller-listings-booklist">'
    40             . nytBestsellerListings::getBookList( $atts['initial-list'], false, $displayImages )
    41             . '</div>' 
     40            . NytBestsellerListings::getBookList( $atts['initial-list'], true, $display_images )
     41            . '</div>'
    4242            . $dropdown;
    4343    else :
     
    4646
    4747    return $out;
    48 
    4948}
  • bestseller-lists-from-new-york-times/trunk/index.php

    r2955023 r2967544  
    44Plugin URI:  https://jakeparis.com/wordpress-plugins/
    55Description: Integrate bestseller lists from the New York Times into your own site with a user-friendly interface.
    6 Version:     2.2.0
    7 Requires PHP: 5.4
    8 Requires at least: 4.9
     6Version:     2.3.0
     7Requires PHP: 7.4
     8Requires at least: 5.4
    99Tested up to: 6.3.0
    1010Author:      Jake Paris
     
    1313License URI: https://opensource.org/licenses/GPL-3.0
    1414*/
     15defined( 'ABSPATH' ) || die( 'Not allowed' );
    1516
    16 define('BSLNYT_PLUGIN_VERSION', '2.2.0');
    17 define('BSLNYT_PLUGIN_PATH', plugin_dir_path(__FILE__) );
    18 define('BSLNYT_PLUGIN_URL', plugins_url('/', __FILE__) );
     17define( 'BSLNYT_PLUGIN_VERSION', '2.3.0' );
     18define( 'BSLNYT_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
     19define( 'BSLNYT_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
    1920
    20 if( function_exists('register_block_type') )
    21     require_once BSLNYT_PLUGIN_PATH . 'blocks/block-registration.php';
    2221
    23 require_once BSLNYT_PLUGIN_PATH . 'nytBestsellerListings.class.php';
     22require_once BSLNYT_PLUGIN_PATH . 'class-nytbestsellerlistings.php';
    2423require_once BSLNYT_PLUGIN_PATH . 'functions.php';
    2524
    26 require_once BSLNYT_PLUGIN_PATH . 'plugin_updates.php';
     25require_once BSLNYT_PLUGIN_PATH . 'plugin-updates.php';
    2726
    28 add_action('wp_enqueue_scripts',function(){
    29     wp_register_script( 'nyt-bestseller-listings', 
    30         BSLNYT_PLUGIN_URL . 'public-assets/build/nyt-bestseller-listings.js',
     27add_action('wp_enqueue_scripts', function () {
     28    wp_register_script( 'nyt-bestseller-listings',
     29        BSLNYT_PLUGIN_URL . 'build/ui/public.js',
    3130        array(
    32             'jquery'
    33         ), 
     31            'jquery',
     32        ),
    3433        BSLNYT_PLUGIN_VERSION
    3534    );
    36     wp_register_style ( 'nyt-bestseller-listings',
    37         BSLNYT_PLUGIN_URL . 'public-assets/build/nyt-bestseller-listings.css',
     35    wp_register_style( 'nyt-bestseller-listings',
     36        BSLNYT_PLUGIN_URL . 'build/ui/public.css',
    3837        array(),
    3938        BSLNYT_PLUGIN_VERSION
    4039    );
    4140
    42     if( ! empty($_SERVER['HTTPS']) )
    43         $js_args = array('ajaxurl' => admin_url( 'admin-ajax.php','https' ) );
    44     else
    45         $js_args = array('ajaxurl' => admin_url( 'admin-ajax.php','http' ) );
     41    if ( ! empty( $_SERVER['HTTPS'] ) ) {
     42        $js_args = array( 'ajaxurl' => admin_url( 'admin-ajax.php', 'https' ) );
     43    } else {
     44        $js_args = array( 'ajaxurl' => admin_url( 'admin-ajax.php', 'http' ) );
     45    }
    4646    wp_localize_script( 'nyt-bestseller-listings', 'nyt_bestseller_listings_settings', $js_args );
    4747});
    4848
    4949
    50 add_action('init',function(){
    51     add_shortcode( 'nyt-bestseller-listings', 'nytBestsellerListings_mainDisplay');
     50add_action('init', function () {
     51    add_shortcode( 'nyt-bestseller-listings', function ( $atts, $content ) {
     52        return wp_kses_post( NytBestsellerListings_mainDisplay( $atts, $content ) );
     53    });
     54
     55    register_block_type( BSLNYT_PLUGIN_PATH . 'build/lists/block.json' );
    5256});
    5357
    54 add_action('admin_menu',function(){
     58
     59add_action('admin_menu', function () {
    5560    add_options_page( 'NYT Bestseller Lists', 'NYT Bestseller Lists', 'activate_plugins', 'nyt-bestseller-lists', 'nytBestSellerListings_adminPage' );
    5661});
    5762
    58 function nytBestSellerListings_adminPage(){
     63function nytBestSellerListings_adminPage() {
    5964    require_once BSLNYT_PLUGIN_PATH . 'admin-page.php';
    6065}
    6166
    6267
    63 add_action('wp_ajax_nyt_bestseller_listings_getList', 'nytBestSellerListings_ajax_getList');
    64 add_action('wp_ajax_nopriv_nyt_bestseller_listings_getList', 'nytBestSellerListings_ajax_getList');
    65 function nytBestSellerListings_ajax_getList(){
    66     $list = $_REQUEST['listName'];
     68add_action( 'wp_ajax_nyt_bestseller_listings_getList', 'nytBestSellerListings_ajax_getList' );
     69add_action( 'wp_ajax_nopriv_nyt_bestseller_listings_getList', 'nytBestSellerListings_ajax_getList' );
     70function nytBestSellerListings_ajax_getList() {
     71    $list = sanitize_text_field( $_GET['listName'] );
    6772
    68     $displayImages = ( isset($_REQUEST['displayImages']) )
    69         ? (bool) $_REQUEST['displayImages']
     73    $display_images = ( isset( $_GET['displayImages'] ) )
     74        ? (bool) $_GET['displayImages']
    7075        : true;
    7176
    72     $html = nytBestsellerListings::getBookList( $list, false, $displayImages );
    73     echo $html;
     77    $html = NytBestsellerListings::getBookList( $list, true, $display_images );
     78    echo wp_kses_post( $html );
    7479    exit;
    7580}
    7681
     82add_action( 'wp_ajax_nyt_bestseller_listings_getAllLists', 'nytBestSellerListings_ajax_getAllLists' );
     83add_action( 'wp_ajax_nopriv_nyt_bestseller_listings_getAllLists', 'nytBestSellerListings_ajax_getAllLists' );
     84function nytBestSellerListings_ajax_getAllLists () {
     85    $all_lists = NytBestsellerListings::getResults( 'names.json' );
     86    $all_lists_configured = [];
     87    if ( ! empty( $all_lists ) ) {
     88        foreach ( $all_lists->results as $list ) {
     89            $all_lists_configured[] = [
     90                'label' => $list->display_name,
     91                'value' => $list->list_name_encoded,
     92            ];
     93        }
     94    }
     95    wp_send_json_success( $all_lists_configured );
     96}
    7797
    78 register_deactivation_hook(__FILE__, function(){
    79     delete_option('nyt_bestseller_listings_apiKey');
    80     delete_option('nyt_bestseller_listings_defaultList');
     98register_deactivation_hook(__FILE__, function () {
     99    delete_option( 'nyt_bestseller_listings_apiKey' );
     100    delete_option( 'nyt_bestseller_listings_defaultList' );
    81101});
  • bestseller-lists-from-new-york-times/trunk/readme.txt

    r2955023 r2967544  
    33Donate link: https://jakeparis.com/
    44Tags: books, library, bestsellers, libraries, reading lists
    5 Requires at least: 4.9
     5Requires at least: 5.4
    66Tested up to: 6.3.0
    77Stable tag: 2.2.0
     
    4646
    4747== Changelog ==
     48
     49= 2.3.0 =
     50
     51Reorganization of plugin; housekeeping.
    4852
    4953= 2.2.0 =
Note: See TracChangeset for help on using the changeset viewer.