Plugin Directory

Changeset 3028651


Ignore:
Timestamp:
01/30/2024 10:03:42 AM (2 years ago)
Author:
wphelpkit
Message:

Update to version 1.0 from GitHub

Location:
wphelpkit
Files:
1058 added
2 deleted
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wphelpkit/tags/1.0/README.txt

    r3027816 r3028651  
    1 === WP HelpKit - Your WordPress savior. Get expert assistance for WordPress, themes, or plugins. ===
     1=== WPHelpKit ===
    22
    33Contributors: wphelpkit
    4 Tags: WPHelpKit, support, help center, knowledge base, documentation, faqs, docs, wiki
    5 Stable tag: 0.9.9
     4Tags: WPHelpKit, knowledge base, documentation, faqs, support, docs, help center, wiki
     5Stable tag: 1.0
    66Requires at least: 5.0
    7 Requires PHP: 7.4.1
     7Requires PHP: 6.4
    88Tested up to: 6.4
    99License: GPL-2.0-or-later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1111
     12Create a fully featured Help Center site (Knowledge Base, Documentation, Wiki, FAQs) with WordPress.
     13
    1214== Description ==
    1315
    14 WP HelpKit is your trusted companion for resolving WordPress-related challenges effortlessly. Whether you're facing issues with WordPress itself, themes, or plugins, our expert team is at your service. With WP HelpKit, you gain access to professional assistance and guidance, ensuring your WordPress journey is smooth and stress-free. Say goodbye to frustrating technical hurdles and hello to a seamless WordPress experience. Get the help you need, when you need it, with WP HelpKit.
     16<strong>Create</strong>, <strong>Organize</strong> and <strong>Publish</strong> help content.
    1517
    16 <h3>What can I do with WP HelpKit?</h3>
     18A simple tool for creating <strong>Knowledge Base</strong> and <strong>Documentation</strong> sites
     19for your software products.
     20
     21<strong>HelpKit</strong> for documentation sites
     22is what WooCommerce is for eCommerce sites.
     23
     24<h3>What can I do with HelpKit?</h3>
    1725<ul>
    18 <li>Get expert assistance for WordPress, themes, or plugins – Hassle-Free.</li>
     26<li>Help Center / Support Sites</li>
     27<li>Knowledge Base</li>
     28<li>Documentation</li>
     29<li>User Manuals</li>
     30<li>Wiki</li>
     31<li>FAQs</li>
    1932</ul>
    2033
     
    2841
    2942= How to get started? =
    30 Upon activation, the plugin will add a new page named "WP HelpKit" which will serve as the index for all your help needs.
     43Upon activation, the plugin will add a new page named "HelpKit" which will serve as the index for all your help articles.
     44
     45= Where do I find the Settings / Customization options =
     46All settings and customization option can be found in Appearance > Customize > Helpkit.
     47
     48= How to add Help articles? =
     49In your WordPress administration dashboard, go to HelpKit > Add New
     50
     51= How to reorder help articles and categories =
     52Open up the HelpKit page via Appearance > Customize and start draging and dropping help article or categories direcly in the livew preview of the Customizer.
    3153
    3254== Changelog ==
    3355
    34 = 0.9.9 =
    35 - Initial Release
     56= 0.9.2 =
     57* New: Index tree navigation added to help articles and categories
     58* New: Option to redirect category to first article
     59* New: Option to search current category Only
     60* New: Search by tags
     61
     62= 0.9.1 =
     63
     64* New: Category descriptions added to HelpKit index page;
     65* New: Category descriptions added for sub-categories;
     66* New: Help Article excerpts added to the category archives;
     67* New in PRO: Assign category images / thumbs;
     68
     69= 0.9.0 =
     70
     71* Initial Release
  • wphelpkit/tags/1.0/wphelpkit.php

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

    r3027816 r3028651  
    1 === WP HelpKit - Your WordPress savior. Get expert assistance for WordPress, themes, or plugins. ===
     1=== WPHelpKit ===
    22
    33Contributors: wphelpkit
    4 Tags: WPHelpKit, support, help center, knowledge base, documentation, faqs, docs, wiki
    5 Stable tag: 0.9.9
     4Tags: WPHelpKit, knowledge base, documentation, faqs, support, docs, help center, wiki
     5Stable tag: 1.0
    66Requires at least: 5.0
    7 Requires PHP: 7.4.1
     7Requires PHP: 6.4
    88Tested up to: 6.4
    99License: GPL-2.0-or-later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1111
     12Create a fully featured Help Center site (Knowledge Base, Documentation, Wiki, FAQs) with WordPress.
     13
    1214== Description ==
    1315
    14 WP HelpKit is your trusted companion for resolving WordPress-related challenges effortlessly. Whether you're facing issues with WordPress itself, themes, or plugins, our expert team is at your service. With WP HelpKit, you gain access to professional assistance and guidance, ensuring your WordPress journey is smooth and stress-free. Say goodbye to frustrating technical hurdles and hello to a seamless WordPress experience. Get the help you need, when you need it, with WP HelpKit.
     16<strong>Create</strong>, <strong>Organize</strong> and <strong>Publish</strong> help content.
    1517
    16 <h3>What can I do with WP HelpKit?</h3>
     18A simple tool for creating <strong>Knowledge Base</strong> and <strong>Documentation</strong> sites
     19for your software products.
     20
     21<strong>HelpKit</strong> for documentation sites
     22is what WooCommerce is for eCommerce sites.
     23
     24<h3>What can I do with HelpKit?</h3>
    1725<ul>
    18 <li>Get expert assistance for WordPress, themes, or plugins – Hassle-Free.</li>
     26<li>Help Center / Support Sites</li>
     27<li>Knowledge Base</li>
     28<li>Documentation</li>
     29<li>User Manuals</li>
     30<li>Wiki</li>
     31<li>FAQs</li>
    1932</ul>
    2033
     
    2841
    2942= How to get started? =
    30 Upon activation, the plugin will add a new page named "WP HelpKit" which will serve as the index for all your help needs.
     43Upon activation, the plugin will add a new page named "HelpKit" which will serve as the index for all your help articles.
     44
     45= Where do I find the Settings / Customization options =
     46All settings and customization option can be found in Appearance > Customize > Helpkit.
     47
     48= How to add Help articles? =
     49In your WordPress administration dashboard, go to HelpKit > Add New
     50
     51= How to reorder help articles and categories =
     52Open up the HelpKit page via Appearance > Customize and start draging and dropping help article or categories direcly in the livew preview of the Customizer.
    3153
    3254== Changelog ==
    3355
    34 = 0.9.9 =
    35 - Initial Release
     56= 0.9.2 =
     57* New: Index tree navigation added to help articles and categories
     58* New: Option to redirect category to first article
     59* New: Option to search current category Only
     60* New: Search by tags
     61
     62= 0.9.1 =
     63
     64* New: Category descriptions added to HelpKit index page;
     65* New: Category descriptions added for sub-categories;
     66* New: Help Article excerpts added to the category archives;
     67* New in PRO: Assign category images / thumbs;
     68
     69= 0.9.0 =
     70
     71* Initial Release
  • wphelpkit/trunk/wphelpkit.php

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