Plugin Directory

Changeset 3027816


Ignore:
Timestamp:
01/28/2024 01:11:59 PM (2 years ago)
Author:
wphelpkit
Message:

Update to version 0.9.9 from GitHub

Location:
wphelpkit
Files:
16 added
18 deleted
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wphelpkit/assets/banner-1544x500.jpg

    • Property svn:mime-type changed from application/octet-stream to image/jpeg
  • wphelpkit/assets/banner-772x250.jpg

    • Property svn:mime-type changed from application/octet-stream to image/jpeg
  • wphelpkit/assets/icon-128x128.jpg

    • Property svn:mime-type changed from application/octet-stream to image/jpeg
  • wphelpkit/assets/icon-256x256.jpg

    • Property svn:mime-type changed from application/octet-stream to image/jpeg
  • wphelpkit/tags/0.9.9/wphelpkit.php

    r2243211 r3027816  
    11<?php
    22
    3 /*
    4  * Plugin Name: HelpKit - Documentation and Knowledge Base WordPress Plugin
    5  * Description: Publish, organize and manage Help Articles for your software product.
    6  * Version: 0.9.2
    7  * Author: WPHelpKit
    8  * Plugin URI: https://wphelpkit.com
    9  * Release Asset: true
    10  * License: GPLv2 or later
    11  * License URI: https://www.gnu.org/licenses/gpl-2.0.html
    12  * Text Domain: wphelpkit
    13  *
    14  */
    15 if ( !defined( 'ABSPATH' ) ) {
    16     exit;
    17 }
    18 if ( !function_exists( 'is_plugin_active' ) ) {
    19     include_once ABSPATH . 'wp-admin/includes/plugin.php';
    20 }
    213/**
    22  * Freemius initialization.
     4 * Plugin Name:             WP HelpKit
     5 * Plugin URI:              https://wphelpkit.com
     6 * Description:             Your WordPress savior. Get expert assistance for WordPress, themes, or plugins – Hassle-Free.
     7 * Version:                 0.9.9
     8 * Author:                  WP HelpKit
     9 * Author URI:              https://wphelpkit.com
     10 * Text Domain:             wphelpkit
     11 * Domain Path:             /languages/
     12 * License:                 GPLv2 or later
     13 * License URI:             https://www.gnu.org/licenses/gpl-2.0.html
     14 * Requires at least:       5.0
     15 * Tested up to:            6.4
    2316 */
    2417
    25 if ( function_exists( 'wphelpkit_fs_init' ) ) {
    26     wphelpkit_fs_init()->set_basename( false, __FILE__ );
    27 } else {
    28    
    29     if ( !function_exists( 'wphelpkit_fs_init' ) ) {
    30         // Create a helper function for easy SDK access.
    31         function wphelpkit_fs_init()
    32         {
    33             global  $wphelpkit_fs_init ;
    34            
    35             if ( !isset( $wphelpkit_fs_init ) ) {
    36                 // Include Freemius SDK.
    37                 require_once dirname( __FILE__ ) . '/freemius/start.php';
    38                 $wphelpkit_fs_init = fs_dynamic_init( array(
    39                     'id'             => '4904',
    40                     'slug'           => 'wphelpkit',
    41                     'premium_slug'   => 'wphelpkit_fs_pro',
    42                     'type'           => 'plugin',
    43                     'public_key'     => 'pk_b16f1368eb9b019f0ea863584229f',
    44                     'is_premium'     => false,
    45                     'premium_suffix' => 'PRO',
    46                     'navigation'     => 'tabs',
    47                     'has_addons'     => false,
    48                     'has_paid_plans' => true,
    49                     'menu'           => array(
    50                     'slug'    => 'wphelpkit-settings',
    51                     'support' => false,
    52                     'parent'  => array(
    53                     'slug' => 'edit.php?post_type=helpkit',
    54                 ),
    55                 ),
    56                     'is_live'        => true,
    57                 ) );
    58             }
    59            
    60             return $wphelpkit_fs_init;
    61         }
    62        
    63         // Init Freemius.
    64         wphelpkit_fs_init();
    65         // Signal that SDK was initiated.
    66         do_action( 'wphelpkit_fs_init_loaded' );
    67     }
     18if ( ! defined( 'ABSPATH' ) ) {
     19    exit;
     20} // Exit if accessed directly
    6821
     22if ( ! function_exists( 'is_plugin_active' ) ) {
     23    require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    6924}
    7025
     26if ( ! class_exists( 'WPHelpKit' ) ) :
    7127
    72 if ( !function_exists( 'wphelpkit_fs_init_custom_connect_message_on_update' ) ) {
    73     // Create a custom opt-in message.
    74     function wphelpkit_fs_init_custom_connect_message_on_update(
    75         $message,
    76         $user_first_name,
    77         $plugin_title,
    78         $user_login,
    79         $site_link,
    80         $freemius_link
    81     )
    82     {
    83         return sprintf(
    84             __( 'Hey %1$s', 'wphelpkit' ) . ',<br>' . __( 'Please help us improve %2$s! If you opt-in, some data about your usage of %2$s will be sent to %5$s. If you skip this, that\'s okay! %2$s will still work just fine.', 'wphelpkit' ),
    85             $user_first_name,
    86             '<b>' . $plugin_title . '</b>',
    87             '<b>' . $user_login . '</b>',
    88             $site_link,
    89             $freemius_link
    90         );
    91     }
    92    
    93     wphelpkit_fs_init()->add_filter(
    94         'connect_message_on_update',
    95         'wphelpkit_fs_init_custom_connect_message_on_update',
    96         10,
    97         6
    98     );
    99 }
     28    class WPHelpKit {
    10029
     30        private static $instance ;
    10131
    102 if ( !class_exists( 'WPHelpKit' ) ) {
    103     require dirname( __FILE__ ) . '/vendor/autoload.php';
    104     /**
    105      * The main plugin class.
    106      *
    107      * @since 0.0.1
    108      * @since 0.0.3 Removed `$settings` propery and `get_option()` method.  Use WPHelpKit_Settings::get_instance()->get_option() instead.
    109      * @since 0.1.1 Renamed class to WPHelpKit_Plugin.
    110      * @since 0.9.0 Renamed class to WPHelpKit.
    111      */
    112     class WPHelpKit
    113     {
    114         /**
    115          * Our static instance.
    116          *
    117          * @since 0.0.1
    118          *
    119          * @var WPHelpKit
    120          */
    121         private static  $instance ;
    122         /**
    123          * Our version number.
    124          *
    125          * @since 0.0.1
    126          *
    127          * @var string
    128          */
    129         const  VERSION = '0.9.0' ;
    130         /**
    131          * Transient name to set when we are activated.
    132          *
    133          * @since 0.6.2
    134          *
    135          * @var string
    136          */
    137         public static  $activated_transient = 'wphelpkit-activated' ;
    138         /**
    139          * Get our instance.
    140          *
    141          * Calling this static method is preferable to calling the class
    142          * constrcutor directly.
    143          *
    144          * @since 0.0.1
    145          *
    146          * @return WPHelpKit
    147          */
    148         public static function get_instance()
     32        public function __construct() {
     33
     34            // Helpers
     35            //include_once( dirname( __FILE__ ) . '/includes/helpers/helpers.php' );
     36
     37            // Dashboard
     38            include_once( dirname( __FILE__ ) . '/inc/dashboard/index.php' );
     39
     40        }
     41
     42        // Ensures only one instance of WPHelpKit is loaded or can be loaded.
     43        public static function get_instance()
    14944        {
    15045            if ( !self::$instance ) {
     
    15348            return self::$instance;
    15449        }
    155        
    156         /**
    157          * Constructor.
    158          *
    159          * Initialize our static instance and add hooks.
    160          *
    161          * @since 0.0.1
    162          */
    163         public function __construct()
    164         {
    165             if ( self::$instance ) {
    166                 return self::$instance;
    167             }
    168             self::$instance = $this;
    169             $this->add_hooks();
    170             if ( is_admin() ) {
    171                 $this->add_admin_hooks();
    172             }
    173         }
    174        
    175         /**
    176          * Add hooks.
    177          *
    178          * @since 0.0.1
    179          *
    180          * @return void
    181          */
    182         protected function add_hooks()
    183         {
    184             global  $wp_filter ;
    185             register_activation_hook( __FILE__, array( $this, 'activate' ) );
    186             add_action( 'plugins_loaded', array( $this, 'setup' ) );
    187             add_action( 'init', array( $this, 'register_scripts_styles' ) );
    188             add_action( 'init', array( $this, 'maybe_create_helpkit_page' ), PHP_INT_MAX );
    189             add_filter(
    190                 'block_categories',
    191                 array( $this, 'block_categories' ),
    192                 10,
    193                 2
    194             );
    195             add_action( 'enqueue_block_editor_assets', array( $this, 'blacklist_blocks' ) );
    196             add_action( 'import_start', array( 'WPHelpKit_Importer', 'get_instance' ) );
    197             return;
    198         }
    199        
    200         /**
    201          * Add admin hooks.
    202          *
    203          * @since 0.1.0
    204          *
    205          * @return void
    206          */
    207         protected function add_admin_hooks()
    208         {
    209             add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
    210             return;
    211         }
    212        
    213         /**
    214          * Perform basic setup operations.
    215          *
    216          * @since 0.0.1
    217          *
    218          * @return void
    219          *
    220          * @action plugins_loaded
    221          */
    222         public function setup()
    223         {
    224             WPHelpKit_Session_Handler::get_instance();
    225             // need to instantiate our Settings before the Article CPT
    226             // since the Article CPT uses the settings when registering
    227             // the post_type/taxomomies
    228             WPHelpKit_Settings::get_instance();
    229             WPHelpKit_Integration::get_instance();
    230             WPHelpKit_Article::get_instance();
    231             WPHelpKit_Article_Category::get_instance();
    232             WPHelpKit_Article_Tag::get_instance();
    233             WPHelpKit_Search::get_instance();
    234             WPHelpKit_Customizer::get_instance();
    235             WPHelpKit_Index_Tree::get_instance();
    236             return;
    237         }
    238        
    239         /**
    240          * Register our scripts and styles.
    241          *
    242          * @since 0.0.1
    243          *
    244          * @return void
    245          *
    246          * @action init
    247          */
    248         public function register_scripts_styles()
    249         {
    250             $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' );
    251             $rtl = ( is_rtl() ? '-rtl' : '' );
    252             $styles = array(
    253                 'wphelpkit-wphelpkiticons' => array(),
    254                 'wphelpkit-styles'         => array(
    255                 'dependencies' => array( 'wphelpkit-wphelpkiticons' ),
    256             ),
    257                 'wphelpkit-admin'          => array(
    258                 'is_admin'     => true,
    259                 'dependencies' => array( 'wphelpkit-wphelpkiticons' ),
    260             ),
    261                 'wphelpkit-order'          => array(
    262                 'is_admin' => true,
    263             ),
    264             );
    265             foreach ( $styles as $handle => $data ) {
    266                 // contruct $src & $dependencies if they are not already set.
    267                 $admin = ( isset( $data['is_admin'] ) && $data['is_admin'] ? 'admin/' : '' );
    268                 $src = ( !isset( $data['src'] ) ? 'assets/css/' . $admin . str_replace( 'wphelpkit-', '', $handle ) : $data['src'] );
    269                 if ( !isset( $data['src'] ) ) {
    270                 }
    271                 $dependencies = ( !isset( $data['dependencies'] ) ? array() : $data['dependencies'] );
    272                 // register the style.
    273                 wp_register_style(
    274                     $handle,
    275                     plugins_url( "{$src}{$rtl}{$suffix}.css", __FILE__ ),
    276                     $dependencies,
    277                     self::VERSION
    278                 );
    279             }
    280             $scripts = array(
    281                 'wphelpkit-customize-preview'   => array(
    282                 'is_admin'     => true,
    283                 'dependencies' => array( 'jquery' ),
    284             ),
    285                 'wphelpkit-customize-controls'  => array(
    286                 'is_admin'     => true,
    287                 'dependencies' => array( 'jquery', 'customize-controls' ),
    288             ),
    289                 'wphelpkit-order'               => array(
    290                 'is_admin'     => true,
    291                 'dependencies' => array( 'jquery-ui-sortable' ),
    292                 'localize'     => array(
    293                 'l10n' => array(
    294                 'ajaxurl'         => admin_url( 'admin-ajax.php' ),
    295                 'category_action' => WPHelpKit_Article_Category::$category_order_action,
    296                 'category_nonce'  => wp_create_nonce( WPHelpKit_Article_Category::$category_order_action . '-nonce' ),
    297                 'article_action'  => WPHelpKit_Article::$article_order_action,
    298                 'article_nonce'   => wp_create_nonce( WPHelpKit_Article::$article_order_action . '-nonce' ),
    299                 'notice'          => esc_html__( 'Page updated.', 'wphelpkit' ),
    300             ),
    301             ),
    302             ),
    303                 'wphelpkit-search-block-editor' => array(
    304                 'src'          => 'assets/js/blocks/dist/search/search',
    305                 'dependencies' => array( 'wp-element' ),
    306                 'localize'     => array(
    307                 'l10n' => array(
    308                 'name' => WPHelpKit_Search::$block,
    309             ),
    310             ),
    311             ),
    312                 'wphelpkit-blacklist-blocks'    => array(
    313                 'is_admin'     => true,
    314                 'dependencies' => array( 'wp-blocks' ),
    315             ),
    316                 'wphelpkit-article-link'        => array(
    317                 'dependencies' => array( 'jquery' ),
    318                 'localize'     => array(
    319                 'l10n' => array(
    320                 'ajaxurl' => admin_url( 'admin-ajax.php' ),
    321                 'action'  => WPHelpKit_Article::$article_link_action,
    322                 'nonce'   => wp_create_nonce( WPHelpKit_Article::$article_link_action . '-nonce' ),
    323             ),
    324             ),
    325             ),
    326             );
    327             foreach ( $scripts as $handle => $data ) {
    328                 // contruct $src, $dependencies & $in_footer if they are not already set.
    329                 $admin = ( isset( $data['is_admin'] ) && $data['is_admin'] ? 'admin/' : '' );
    330                 $src = ( !isset( $data['src'] ) ? 'assets/js/' . $admin . str_replace( 'wphelpkit-', '', $handle ) : $data['src'] );
    331                 $dependencies = ( !isset( $data['dependencies'] ) ? array() : $data['dependencies'] );
    332                 $in_footer = ( !isset( $data['in_footer'] ) ? true : $data['in_footer'] );
    333                 // register the script.
    334                 wp_register_script(
    335                     $handle,
    336                     plugins_url( "{$src}{$suffix}.js", __FILE__ ),
    337                     $dependencies,
    338                     self::VERSION,
    339                     $in_footer
    340                 );
    341                 // localize the script if necessary.
    342                
    343                 if ( isset( $data['localize'] ) ) {
    344                     // contruct $object_name if not already set.
    345                     $object_name = ( !isset( $data['localize']['object_name'] ) ? str_replace( '-', '_', $handle ) : $data['localize']['object_name'] );
    346                     // localize the script.
    347                     wp_localize_script( $handle, $object_name, $data['localize']['l10n'] );
    348                 }
    349            
    350             }
    351             return;
    352         }
    353        
    354         /**
    355          * Enqueue our admin scripts and styles.
    356          *
    357          * @since 0.1.0
    358          *
    359          * @return void
    360          *
    361          * @action admin_enqueue_scripts
    362          */
    363         public function admin_enqueue_scripts()
    364         {
    365             global  $pagenow ;
    366             wp_enqueue_style( 'wphelpkit-admin' );
    367             return;
    368         }
    369        
    370         /**
    371          * Add a new "block category" for our blocks.
    372          *
    373          * @since 0.1.0
    374          *
    375          * @param array $categories
    376          * @param WP_Post $post
    377          * @return array
    378          */
    379         public function block_categories( $categories, $post )
    380         {
    381             $category = array( array(
    382                 'slug'  => 'wphelpkit',
    383                 'title' => esc_html__( 'WPHelpKit', 'wphelpkit' ),
    384             ) );
    385             $categories = array_merge( $categories, $category );
    386             return $categories;
    387         }
    388        
    389         /**
    390          * Only allow our blocks for specific post type(s).
    391          *
    392          * @since 0.0.5
    393          *
    394          * @return void
    395          */
    396         public function blacklist_blocks()
    397         {
    398             global  $post ;
    399             if ( 'page' === get_post_type( $post ) ) {
    400                 return;
    401             }
    402             wp_enqueue_script( 'wphelpkit-blacklist-blocks' );
    403             return;
    404         }
    405        
    406         /**
    407          * Check WP version
    408          *
    409          * @since 0.9.2
    410          *
    411          * @param string $operator used for comparation
    412          * @param string $version used for comparation
    413          * @return bool value of comparison
    414          */
    415         public static function is_wp_version( $operator, $version )
    416         {
    417             global  $wp_version ;
    418             return version_compare( $wp_version, $version, $operator );
    419         }
    420        
    421         /**
    422          * Is the user "previewing" something in Gutenberg?
    423          *
    424          * @since 0.0.5
    425          * @since 0.9.2 use is_block_editor() to determine if current page is a
    426          * gutenberg editor page when WP >= 5.3.2
    427          *
    428          * @return bool True if prevewing, false otherwise.
    429          */
    430         public static function is_gutenberg_preview()
    431         {
    432             if ( !self::is_wp_version( '>=', '5.3.2' ) || !function_exists( 'get_current_screen' ) ) {
    433                 return isset( $_REQUEST['context'] ) && 'edit' === $_REQUEST['context'];
    434             }
    435             $current_screen = get_current_screen();
    436             if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
    437                 // Gutenberg page on 5.3.2+.
    438                 return true;
    439             }
    440             return false;
    441         }
    442        
    443         /**
    444          * Is the user "previewing" something either in the Customizer or in Gutenberg?
    445          *
    446          * @since 0.0.5
    447          *
    448          * @return bool True if prevewing, false otherwise.
    449          */
    450         public static function is_previewing()
    451         {
    452             return is_customize_preview() || self::is_gutenberg_preview();
    453         }
    454        
    455         /**
    456          * Set a transient on plugin activation, so the next hit knows we were just activated.
    457          *
    458          * @since 0.6.1
    459          *
    460          * @return void
    461          *
    462          * @action activate_wp-helpkit/plugin.php
    463          */
    464         public function activate()
    465         {
    466             set_transient( self::$activated_transient, true );
    467             // flush the rewrite rules after registering post_type and taxonomies.
    468             set_transient( WPHelpKit_Article::$flush_rewrite_rules_transient, true );
    469             return;
    470         }
    471        
    472         /**
    473          * On plugin activation, create a page to use as the HelpKit archive.
    474          *
    475          * @since 0.6.1
    476          *
    477          * @return void
    478          *
    479          * @action init
    480          */
    481         public function maybe_create_helpkit_page()
    482         {
    483             $settings = WPHelpKit_Settings::get_instance();
    484             $activated = get_transient( self::$activated_transient );
    485             if ( !$activated ) {
    486                 return;
    487             }
    488             delete_transient( self::$activated_transient );
    489             $archive_info = WPHelpKit_Archive_Info::get_instance();
    490             if ( 'default' !== $archive_info->type ) {
    491                 // archive already set.
    492                 return;
    493             }
    494             // create an archive page.
    495             $title = esc_html__( 'HelpKit', 'wphelpkit' );
    496             $slug = 'helpkit';
    497             /**
    498              * Filters the title of the default HelpKit archive page.
    499              *
    500              * @since 0.6.1
    501              *
    502              * @param string $title The title of the page.
    503              */
    504             $title = apply_filters( 'wphelpkit-default-archive-page-title', $title );
    505             $postarr = array(
    506                 'post_type'    => 'page',
    507                 'post_title'   => $title,
    508                 'post_name'    => $slug,
    509                 'post_status'  => 'publish',
    510                 'post_content' => '',
    511             );
    512             $page_id = wp_insert_post( $postarr );
    513             // set the new page as the index_page.
    514             if ( isset( $page_id ) && !empty($page_id) ) {
    515                 $settings->set_option( 'index_page', $page_id );
    516             }
    517             return;
    518         }
    519    
    520     }
    521     // instantiate ourselves
    522     WPHelpKit::get_instance();
    523 }
    52450
    525 if ( !function_exists( 'wp_is_json_request' ) ) {
    526     /**
    527      * Checks whether current request is a JSON request, or is expecting a JSON response.
    528      *
    529      * @since 0.2.0
    530      * @since WP Core 5.0.0
    531      *
    532      * @return bool True if Accepts or Content-Type headers contain application/json, false otherwise.
    533      */
    534     function wp_is_json_request()
    535     {
    536         if ( isset( $_SERVER['HTTP_ACCEPT'] ) && false !== strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) ) {
    537             return true;
    538         }
    539         if ( isset( $_SERVER['CONTENT_TYPE'] ) && 'application/json' === $_SERVER['CONTENT_TYPE'] ) {
    540             return true;
    541         }
    542         return false;
    543     }
     51    }
    54452
    545 }
    546 if ( !function_exists( 'has_block' ) ) {
    547     /**
    548      * Shim for has_block() in 5.0 Core or Gutenberg plugin 3.6.0+, so that we
    549      * don't have to continually write `function_exists( 'has_block' ) && has_block( 'wphelpkit/foo' )`.
    550      *
    551      * @since 0.5.0
    552      *
    553      * @param string                  $block_type Full Block type to look for.
    554      * @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object. Defaults to global $post.
    555      * @return bool If WP < 5.0 || Gutenberg not active always return false.
    556      */
    557     function has_block( $block_type, $post = null )
    558     {
    559         return false;
    560     }
     53    WPHelpKit::get_instance();
    56154
    562 }
    563 if ( !function_exists( 'has_block_editor' ) ) {
    564     /**
    565      * Check if Block Editor is available.
    566      * Must only be used after plugins_loaded action is fired.
    567      *
    568      * @since 0.6.1
    569      *
    570      * @return bool
    571      */
    572     function has_block_editor()
    573     {
    574         // Block editor since 5.0.
    575         $five0 = version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' );
    576         // Gutenberg plugin is installed and activated.
    577         $gutenberg = is_plugin_active( 'gutenberg/gutenberg.php' );
    578         if ( $five0 || $gutenberg ) {
    579             return true;
    580         }
    581         return false;
    582     }
    583 
    584 }
     55endif;
  • wphelpkit/trunk/wphelpkit.php

    r2243211 r3027816  
    11<?php
    22
    3 /*
    4  * Plugin Name: HelpKit - Documentation and Knowledge Base WordPress Plugin
    5  * Description: Publish, organize and manage Help Articles for your software product.
    6  * Version: 0.9.2
    7  * Author: WPHelpKit
    8  * Plugin URI: https://wphelpkit.com
    9  * Release Asset: true
    10  * License: GPLv2 or later
    11  * License URI: https://www.gnu.org/licenses/gpl-2.0.html
    12  * Text Domain: wphelpkit
    13  *
    14  */
    15 if ( !defined( 'ABSPATH' ) ) {
    16     exit;
    17 }
    18 if ( !function_exists( 'is_plugin_active' ) ) {
    19     include_once ABSPATH . 'wp-admin/includes/plugin.php';
    20 }
    213/**
    22  * Freemius initialization.
     4 * Plugin Name:             WP HelpKit
     5 * Plugin URI:              https://wphelpkit.com
     6 * Description:             Your WordPress savior. Get expert assistance for WordPress, themes, or plugins – Hassle-Free.
     7 * Version:                 0.9.9
     8 * Author:                  WP HelpKit
     9 * Author URI:              https://wphelpkit.com
     10 * Text Domain:             wphelpkit
     11 * Domain Path:             /languages/
     12 * License:                 GPLv2 or later
     13 * License URI:             https://www.gnu.org/licenses/gpl-2.0.html
     14 * Requires at least:       5.0
     15 * Tested up to:            6.4
    2316 */
    2417
    25 if ( function_exists( 'wphelpkit_fs_init' ) ) {
    26     wphelpkit_fs_init()->set_basename( false, __FILE__ );
    27 } else {
    28    
    29     if ( !function_exists( 'wphelpkit_fs_init' ) ) {
    30         // Create a helper function for easy SDK access.
    31         function wphelpkit_fs_init()
    32         {
    33             global  $wphelpkit_fs_init ;
    34            
    35             if ( !isset( $wphelpkit_fs_init ) ) {
    36                 // Include Freemius SDK.
    37                 require_once dirname( __FILE__ ) . '/freemius/start.php';
    38                 $wphelpkit_fs_init = fs_dynamic_init( array(
    39                     'id'             => '4904',
    40                     'slug'           => 'wphelpkit',
    41                     'premium_slug'   => 'wphelpkit_fs_pro',
    42                     'type'           => 'plugin',
    43                     'public_key'     => 'pk_b16f1368eb9b019f0ea863584229f',
    44                     'is_premium'     => false,
    45                     'premium_suffix' => 'PRO',
    46                     'navigation'     => 'tabs',
    47                     'has_addons'     => false,
    48                     'has_paid_plans' => true,
    49                     'menu'           => array(
    50                     'slug'    => 'wphelpkit-settings',
    51                     'support' => false,
    52                     'parent'  => array(
    53                     'slug' => 'edit.php?post_type=helpkit',
    54                 ),
    55                 ),
    56                     'is_live'        => true,
    57                 ) );
    58             }
    59            
    60             return $wphelpkit_fs_init;
    61         }
    62        
    63         // Init Freemius.
    64         wphelpkit_fs_init();
    65         // Signal that SDK was initiated.
    66         do_action( 'wphelpkit_fs_init_loaded' );
    67     }
     18if ( ! defined( 'ABSPATH' ) ) {
     19    exit;
     20} // Exit if accessed directly
    6821
     22if ( ! function_exists( 'is_plugin_active' ) ) {
     23    require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    6924}
    7025
     26if ( ! class_exists( 'WPHelpKit' ) ) :
    7127
    72 if ( !function_exists( 'wphelpkit_fs_init_custom_connect_message_on_update' ) ) {
    73     // Create a custom opt-in message.
    74     function wphelpkit_fs_init_custom_connect_message_on_update(
    75         $message,
    76         $user_first_name,
    77         $plugin_title,
    78         $user_login,
    79         $site_link,
    80         $freemius_link
    81     )
    82     {
    83         return sprintf(
    84             __( 'Hey %1$s', 'wphelpkit' ) . ',<br>' . __( 'Please help us improve %2$s! If you opt-in, some data about your usage of %2$s will be sent to %5$s. If you skip this, that\'s okay! %2$s will still work just fine.', 'wphelpkit' ),
    85             $user_first_name,
    86             '<b>' . $plugin_title . '</b>',
    87             '<b>' . $user_login . '</b>',
    88             $site_link,
    89             $freemius_link
    90         );
    91     }
    92    
    93     wphelpkit_fs_init()->add_filter(
    94         'connect_message_on_update',
    95         'wphelpkit_fs_init_custom_connect_message_on_update',
    96         10,
    97         6
    98     );
    99 }
     28    class WPHelpKit {
    10029
     30        private static $instance ;
    10131
    102 if ( !class_exists( 'WPHelpKit' ) ) {
    103     require dirname( __FILE__ ) . '/vendor/autoload.php';
    104     /**
    105      * The main plugin class.
    106      *
    107      * @since 0.0.1
    108      * @since 0.0.3 Removed `$settings` propery and `get_option()` method.  Use WPHelpKit_Settings::get_instance()->get_option() instead.
    109      * @since 0.1.1 Renamed class to WPHelpKit_Plugin.
    110      * @since 0.9.0 Renamed class to WPHelpKit.
    111      */
    112     class WPHelpKit
    113     {
    114         /**
    115          * Our static instance.
    116          *
    117          * @since 0.0.1
    118          *
    119          * @var WPHelpKit
    120          */
    121         private static  $instance ;
    122         /**
    123          * Our version number.
    124          *
    125          * @since 0.0.1
    126          *
    127          * @var string
    128          */
    129         const  VERSION = '0.9.0' ;
    130         /**
    131          * Transient name to set when we are activated.
    132          *
    133          * @since 0.6.2
    134          *
    135          * @var string
    136          */
    137         public static  $activated_transient = 'wphelpkit-activated' ;
    138         /**
    139          * Get our instance.
    140          *
    141          * Calling this static method is preferable to calling the class
    142          * constrcutor directly.
    143          *
    144          * @since 0.0.1
    145          *
    146          * @return WPHelpKit
    147          */
    148         public static function get_instance()
     32        public function __construct() {
     33
     34            // Helpers
     35            //include_once( dirname( __FILE__ ) . '/includes/helpers/helpers.php' );
     36
     37            // Dashboard
     38            include_once( dirname( __FILE__ ) . '/inc/dashboard/index.php' );
     39
     40        }
     41
     42        // Ensures only one instance of WPHelpKit is loaded or can be loaded.
     43        public static function get_instance()
    14944        {
    15045            if ( !self::$instance ) {
     
    15348            return self::$instance;
    15449        }
    155        
    156         /**
    157          * Constructor.
    158          *
    159          * Initialize our static instance and add hooks.
    160          *
    161          * @since 0.0.1
    162          */
    163         public function __construct()
    164         {
    165             if ( self::$instance ) {
    166                 return self::$instance;
    167             }
    168             self::$instance = $this;
    169             $this->add_hooks();
    170             if ( is_admin() ) {
    171                 $this->add_admin_hooks();
    172             }
    173         }
    174        
    175         /**
    176          * Add hooks.
    177          *
    178          * @since 0.0.1
    179          *
    180          * @return void
    181          */
    182         protected function add_hooks()
    183         {
    184             global  $wp_filter ;
    185             register_activation_hook( __FILE__, array( $this, 'activate' ) );
    186             add_action( 'plugins_loaded', array( $this, 'setup' ) );
    187             add_action( 'init', array( $this, 'register_scripts_styles' ) );
    188             add_action( 'init', array( $this, 'maybe_create_helpkit_page' ), PHP_INT_MAX );
    189             add_filter(
    190                 'block_categories',
    191                 array( $this, 'block_categories' ),
    192                 10,
    193                 2
    194             );
    195             add_action( 'enqueue_block_editor_assets', array( $this, 'blacklist_blocks' ) );
    196             add_action( 'import_start', array( 'WPHelpKit_Importer', 'get_instance' ) );
    197             return;
    198         }
    199        
    200         /**
    201          * Add admin hooks.
    202          *
    203          * @since 0.1.0
    204          *
    205          * @return void
    206          */
    207         protected function add_admin_hooks()
    208         {
    209             add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
    210             return;
    211         }
    212        
    213         /**
    214          * Perform basic setup operations.
    215          *
    216          * @since 0.0.1
    217          *
    218          * @return void
    219          *
    220          * @action plugins_loaded
    221          */
    222         public function setup()
    223         {
    224             WPHelpKit_Session_Handler::get_instance();
    225             // need to instantiate our Settings before the Article CPT
    226             // since the Article CPT uses the settings when registering
    227             // the post_type/taxomomies
    228             WPHelpKit_Settings::get_instance();
    229             WPHelpKit_Integration::get_instance();
    230             WPHelpKit_Article::get_instance();
    231             WPHelpKit_Article_Category::get_instance();
    232             WPHelpKit_Article_Tag::get_instance();
    233             WPHelpKit_Search::get_instance();
    234             WPHelpKit_Customizer::get_instance();
    235             WPHelpKit_Index_Tree::get_instance();
    236             return;
    237         }
    238        
    239         /**
    240          * Register our scripts and styles.
    241          *
    242          * @since 0.0.1
    243          *
    244          * @return void
    245          *
    246          * @action init
    247          */
    248         public function register_scripts_styles()
    249         {
    250             $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' );
    251             $rtl = ( is_rtl() ? '-rtl' : '' );
    252             $styles = array(
    253                 'wphelpkit-wphelpkiticons' => array(),
    254                 'wphelpkit-styles'         => array(
    255                 'dependencies' => array( 'wphelpkit-wphelpkiticons' ),
    256             ),
    257                 'wphelpkit-admin'          => array(
    258                 'is_admin'     => true,
    259                 'dependencies' => array( 'wphelpkit-wphelpkiticons' ),
    260             ),
    261                 'wphelpkit-order'          => array(
    262                 'is_admin' => true,
    263             ),
    264             );
    265             foreach ( $styles as $handle => $data ) {
    266                 // contruct $src & $dependencies if they are not already set.
    267                 $admin = ( isset( $data['is_admin'] ) && $data['is_admin'] ? 'admin/' : '' );
    268                 $src = ( !isset( $data['src'] ) ? 'assets/css/' . $admin . str_replace( 'wphelpkit-', '', $handle ) : $data['src'] );
    269                 if ( !isset( $data['src'] ) ) {
    270                 }
    271                 $dependencies = ( !isset( $data['dependencies'] ) ? array() : $data['dependencies'] );
    272                 // register the style.
    273                 wp_register_style(
    274                     $handle,
    275                     plugins_url( "{$src}{$rtl}{$suffix}.css", __FILE__ ),
    276                     $dependencies,
    277                     self::VERSION
    278                 );
    279             }
    280             $scripts = array(
    281                 'wphelpkit-customize-preview'   => array(
    282                 'is_admin'     => true,
    283                 'dependencies' => array( 'jquery' ),
    284             ),
    285                 'wphelpkit-customize-controls'  => array(
    286                 'is_admin'     => true,
    287                 'dependencies' => array( 'jquery', 'customize-controls' ),
    288             ),
    289                 'wphelpkit-order'               => array(
    290                 'is_admin'     => true,
    291                 'dependencies' => array( 'jquery-ui-sortable' ),
    292                 'localize'     => array(
    293                 'l10n' => array(
    294                 'ajaxurl'         => admin_url( 'admin-ajax.php' ),
    295                 'category_action' => WPHelpKit_Article_Category::$category_order_action,
    296                 'category_nonce'  => wp_create_nonce( WPHelpKit_Article_Category::$category_order_action . '-nonce' ),
    297                 'article_action'  => WPHelpKit_Article::$article_order_action,
    298                 'article_nonce'   => wp_create_nonce( WPHelpKit_Article::$article_order_action . '-nonce' ),
    299                 'notice'          => esc_html__( 'Page updated.', 'wphelpkit' ),
    300             ),
    301             ),
    302             ),
    303                 'wphelpkit-search-block-editor' => array(
    304                 'src'          => 'assets/js/blocks/dist/search/search',
    305                 'dependencies' => array( 'wp-element' ),
    306                 'localize'     => array(
    307                 'l10n' => array(
    308                 'name' => WPHelpKit_Search::$block,
    309             ),
    310             ),
    311             ),
    312                 'wphelpkit-blacklist-blocks'    => array(
    313                 'is_admin'     => true,
    314                 'dependencies' => array( 'wp-blocks' ),
    315             ),
    316                 'wphelpkit-article-link'        => array(
    317                 'dependencies' => array( 'jquery' ),
    318                 'localize'     => array(
    319                 'l10n' => array(
    320                 'ajaxurl' => admin_url( 'admin-ajax.php' ),
    321                 'action'  => WPHelpKit_Article::$article_link_action,
    322                 'nonce'   => wp_create_nonce( WPHelpKit_Article::$article_link_action . '-nonce' ),
    323             ),
    324             ),
    325             ),
    326             );
    327             foreach ( $scripts as $handle => $data ) {
    328                 // contruct $src, $dependencies & $in_footer if they are not already set.
    329                 $admin = ( isset( $data['is_admin'] ) && $data['is_admin'] ? 'admin/' : '' );
    330                 $src = ( !isset( $data['src'] ) ? 'assets/js/' . $admin . str_replace( 'wphelpkit-', '', $handle ) : $data['src'] );
    331                 $dependencies = ( !isset( $data['dependencies'] ) ? array() : $data['dependencies'] );
    332                 $in_footer = ( !isset( $data['in_footer'] ) ? true : $data['in_footer'] );
    333                 // register the script.
    334                 wp_register_script(
    335                     $handle,
    336                     plugins_url( "{$src}{$suffix}.js", __FILE__ ),
    337                     $dependencies,
    338                     self::VERSION,
    339                     $in_footer
    340                 );
    341                 // localize the script if necessary.
    342                
    343                 if ( isset( $data['localize'] ) ) {
    344                     // contruct $object_name if not already set.
    345                     $object_name = ( !isset( $data['localize']['object_name'] ) ? str_replace( '-', '_', $handle ) : $data['localize']['object_name'] );
    346                     // localize the script.
    347                     wp_localize_script( $handle, $object_name, $data['localize']['l10n'] );
    348                 }
    349            
    350             }
    351             return;
    352         }
    353        
    354         /**
    355          * Enqueue our admin scripts and styles.
    356          *
    357          * @since 0.1.0
    358          *
    359          * @return void
    360          *
    361          * @action admin_enqueue_scripts
    362          */
    363         public function admin_enqueue_scripts()
    364         {
    365             global  $pagenow ;
    366             wp_enqueue_style( 'wphelpkit-admin' );
    367             return;
    368         }
    369        
    370         /**
    371          * Add a new "block category" for our blocks.
    372          *
    373          * @since 0.1.0
    374          *
    375          * @param array $categories
    376          * @param WP_Post $post
    377          * @return array
    378          */
    379         public function block_categories( $categories, $post )
    380         {
    381             $category = array( array(
    382                 'slug'  => 'wphelpkit',
    383                 'title' => esc_html__( 'WPHelpKit', 'wphelpkit' ),
    384             ) );
    385             $categories = array_merge( $categories, $category );
    386             return $categories;
    387         }
    388        
    389         /**
    390          * Only allow our blocks for specific post type(s).
    391          *
    392          * @since 0.0.5
    393          *
    394          * @return void
    395          */
    396         public function blacklist_blocks()
    397         {
    398             global  $post ;
    399             if ( 'page' === get_post_type( $post ) ) {
    400                 return;
    401             }
    402             wp_enqueue_script( 'wphelpkit-blacklist-blocks' );
    403             return;
    404         }
    405        
    406         /**
    407          * Check WP version
    408          *
    409          * @since 0.9.2
    410          *
    411          * @param string $operator used for comparation
    412          * @param string $version used for comparation
    413          * @return bool value of comparison
    414          */
    415         public static function is_wp_version( $operator, $version )
    416         {
    417             global  $wp_version ;
    418             return version_compare( $wp_version, $version, $operator );
    419         }
    420        
    421         /**
    422          * Is the user "previewing" something in Gutenberg?
    423          *
    424          * @since 0.0.5
    425          * @since 0.9.2 use is_block_editor() to determine if current page is a
    426          * gutenberg editor page when WP >= 5.3.2
    427          *
    428          * @return bool True if prevewing, false otherwise.
    429          */
    430         public static function is_gutenberg_preview()
    431         {
    432             if ( !self::is_wp_version( '>=', '5.3.2' ) || !function_exists( 'get_current_screen' ) ) {
    433                 return isset( $_REQUEST['context'] ) && 'edit' === $_REQUEST['context'];
    434             }
    435             $current_screen = get_current_screen();
    436             if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
    437                 // Gutenberg page on 5.3.2+.
    438                 return true;
    439             }
    440             return false;
    441         }
    442        
    443         /**
    444          * Is the user "previewing" something either in the Customizer or in Gutenberg?
    445          *
    446          * @since 0.0.5
    447          *
    448          * @return bool True if prevewing, false otherwise.
    449          */
    450         public static function is_previewing()
    451         {
    452             return is_customize_preview() || self::is_gutenberg_preview();
    453         }
    454        
    455         /**
    456          * Set a transient on plugin activation, so the next hit knows we were just activated.
    457          *
    458          * @since 0.6.1
    459          *
    460          * @return void
    461          *
    462          * @action activate_wp-helpkit/plugin.php
    463          */
    464         public function activate()
    465         {
    466             set_transient( self::$activated_transient, true );
    467             // flush the rewrite rules after registering post_type and taxonomies.
    468             set_transient( WPHelpKit_Article::$flush_rewrite_rules_transient, true );
    469             return;
    470         }
    471        
    472         /**
    473          * On plugin activation, create a page to use as the HelpKit archive.
    474          *
    475          * @since 0.6.1
    476          *
    477          * @return void
    478          *
    479          * @action init
    480          */
    481         public function maybe_create_helpkit_page()
    482         {
    483             $settings = WPHelpKit_Settings::get_instance();
    484             $activated = get_transient( self::$activated_transient );
    485             if ( !$activated ) {
    486                 return;
    487             }
    488             delete_transient( self::$activated_transient );
    489             $archive_info = WPHelpKit_Archive_Info::get_instance();
    490             if ( 'default' !== $archive_info->type ) {
    491                 // archive already set.
    492                 return;
    493             }
    494             // create an archive page.
    495             $title = esc_html__( 'HelpKit', 'wphelpkit' );
    496             $slug = 'helpkit';
    497             /**
    498              * Filters the title of the default HelpKit archive page.
    499              *
    500              * @since 0.6.1
    501              *
    502              * @param string $title The title of the page.
    503              */
    504             $title = apply_filters( 'wphelpkit-default-archive-page-title', $title );
    505             $postarr = array(
    506                 'post_type'    => 'page',
    507                 'post_title'   => $title,
    508                 'post_name'    => $slug,
    509                 'post_status'  => 'publish',
    510                 'post_content' => '',
    511             );
    512             $page_id = wp_insert_post( $postarr );
    513             // set the new page as the index_page.
    514             if ( isset( $page_id ) && !empty($page_id) ) {
    515                 $settings->set_option( 'index_page', $page_id );
    516             }
    517             return;
    518         }
    519    
    520     }
    521     // instantiate ourselves
    522     WPHelpKit::get_instance();
    523 }
    52450
    525 if ( !function_exists( 'wp_is_json_request' ) ) {
    526     /**
    527      * Checks whether current request is a JSON request, or is expecting a JSON response.
    528      *
    529      * @since 0.2.0
    530      * @since WP Core 5.0.0
    531      *
    532      * @return bool True if Accepts or Content-Type headers contain application/json, false otherwise.
    533      */
    534     function wp_is_json_request()
    535     {
    536         if ( isset( $_SERVER['HTTP_ACCEPT'] ) && false !== strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) ) {
    537             return true;
    538         }
    539         if ( isset( $_SERVER['CONTENT_TYPE'] ) && 'application/json' === $_SERVER['CONTENT_TYPE'] ) {
    540             return true;
    541         }
    542         return false;
    543     }
     51    }
    54452
    545 }
    546 if ( !function_exists( 'has_block' ) ) {
    547     /**
    548      * Shim for has_block() in 5.0 Core or Gutenberg plugin 3.6.0+, so that we
    549      * don't have to continually write `function_exists( 'has_block' ) && has_block( 'wphelpkit/foo' )`.
    550      *
    551      * @since 0.5.0
    552      *
    553      * @param string                  $block_type Full Block type to look for.
    554      * @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object. Defaults to global $post.
    555      * @return bool If WP < 5.0 || Gutenberg not active always return false.
    556      */
    557     function has_block( $block_type, $post = null )
    558     {
    559         return false;
    560     }
     53    WPHelpKit::get_instance();
    56154
    562 }
    563 if ( !function_exists( 'has_block_editor' ) ) {
    564     /**
    565      * Check if Block Editor is available.
    566      * Must only be used after plugins_loaded action is fired.
    567      *
    568      * @since 0.6.1
    569      *
    570      * @return bool
    571      */
    572     function has_block_editor()
    573     {
    574         // Block editor since 5.0.
    575         $five0 = version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' );
    576         // Gutenberg plugin is installed and activated.
    577         $gutenberg = is_plugin_active( 'gutenberg/gutenberg.php' );
    578         if ( $five0 || $gutenberg ) {
    579             return true;
    580         }
    581         return false;
    582     }
    583 
    584 }
     55endif;
Note: See TracChangeset for help on using the changeset viewer.