PHP code example of publishpress / wordpress-reviews

1. Go to this page and download the library: Download publishpress/wordpress-reviews library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

publishpress / wordpress-reviews example snippets





is_admin() && current_user_can('edit_posts')



use PublishPress\WordPressReviews\ReviewsController;

class MyPlugin
{
    /**
    * @var  ReviewsController
    */
    private $reviewController;
    
    public function __construct()
    {
        $this->reviewController = new ReviewsController(
            'my-plugin',
            'My Plugin',
            MY_PLUGIN_URL . '/assets/img/logo.png'
        );
    }
    
    public function init()
    {
        // .......
        add_filter('my-plugin_wp_reviews_allow_display_notice', [$this, 'shouldDisplayBanner']);
        
        $this->reviewController->init();
    }
    
    public function shouldDisplayBanner($shouldDisplay)
    {
        global $pagenow;

        if (! is_admin() || ! current_user_can('edit_posts')) {
            return false;
        }

        if ($pagenow === 'admin.php' && isset($_GET['page'])) {
            if ($_GET['page'] === 'pp-page1') {
                return true;
            }

            if ($_GET['page'] === 'pp-page2') {
                return true;
            }
        }

        if ($pagenow === 'edit.php' && isset($_GET['post_type'])) {
            if ($_GET['post_type'] === 'pp_custom_post_type') {
                return true;
            }
        }

        return false;
    }
    
    // .......
}

add_filter('my-plugin_wp_reviews_allow_display_notice', [$this, 'shouldDisplayBanner'], 20);

 /**
 * @param $shouldDisplay
 * @return bool|null
 */
public function shouldDisplayBanner($shouldDisplay)
{
    global $pagenow;

    if ($shouldDisplay) {
        return true;
    }
    
    if ($pagenow === 'edit.php' && isset($_GET['post_type'])) {
        if ($_GET['post_type'] === 'custom-posttype') {
            return true;
        }
    }

    return $shouldDisplay;
}

[
    'action_ajax_handler' => $this->pluginSlug . '_action',
    'option_installed_on' => $this->pluginSlug . '_wp_reviews_installed_on',
    'nonce_action' => $this->pluginSlug . '_wp_reviews_action',
    'user_meta_dismissed_triggers' => '_' . $this->pluginSlug . '_wp_reviews_dismissed_triggers',
    'user_meta_last_dismissed' => '_' . $this->pluginSlug . '_wp_reviews_last_dismissed',
    'user_meta_already_did' => '_' . $this->pluginSlug . '_wp_reviews_already_did',
    'filter_triggers' => $this->pluginSlug . '_wp_reviews_triggers',
]



add_filter('my-plugin_wp_reviews_meta_map', 'my_plugin_wp_reviews_meta_map');

function my_plugin_wp_reviews_meta_map($metaMap)
{
    // You can override all the array, or specific keys.
    $metaMap = [
        'action_ajax_handler' => 'legacy_slug_ajax_action',
        'option_installed_on' => 'legacy_slug_wp_reviews_installed_on',
        'nonce_action' => 'legacy_slug_wp_reviews_action',
        'user_meta_dismissed_triggers' => '_legacy_slug_wp_reviews_dismissed_triggers',
        'user_meta_last_dismissed' => '_legacy_slug_wp_reviews_last_dismissed',
        'user_meta_already_did' => '_legacy_slug_wp_reviews_already_did',
        'filter_triggers' => 'legacy_slug_wp_reviews_triggers',
    ];

    return $metaMap;
}