Plugin code

This commit is contained in:
janine 2024-03-01 19:04:22 +05:30
parent 8819c70d0e
commit 2fde6edfdc
28 changed files with 6338 additions and 0 deletions

View file

@ -0,0 +1,37 @@
<?php
/**
* Define the internationalization functionality.
*
* Loads and defines the internationalization files for WDL
* so that it is ready for translation.
*
* @link https://chykalophia.com/woocommerce-direct-links
* @since 0.1.0
* @package Woocommerce_Direct_Links
* @subpackage Woocommerce_Direct_Links/includes
* @author Joel Sanguenza <joel@chykalophia.com>,
* Lord Francis Navarro <francis@chykalophia.com>
*/
if ( ! class_exists( 'Cklph_Wdl_i18n' ) ) {
/**
* Internationalization class
*/
class Cklph_Wdl_I18n {
/**
* Load wdl text domain for translation.
*
* @since 0.1.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain(
'plugin-name',
false,
dirname( dirname( CKLPH_WDL_BASE ) ) . '/languages/'
);
}
}
}

View file

@ -0,0 +1,122 @@
<?php
/**
* Register all actions and filters for WDL.
*
* @link https://chykalophia.com/woocommerce-direct-links
* @since 0.1.0
* @package Woocommerce_Direct_Links
* @subpackage Woocommerce_Direct_Links/includes
* @author Joel Sanguenza <joel@chykalophia.com>,
* Lord Francis Navarro <francis@chykalophia.com>
*/
if ( ! class_exists( 'Cklph_Wdl_Loader' ) ) {
/**
* Loader of all actions and filters for WooCommerce direct links.
*/
class Cklph_Wdl_Loader {
/**
* The array of actions registered with WordPress.
*
* @since 0.1.0
* @access protected
* @var array $actions The actions registered with WordPress to fire when wdl loads.
*/
protected $actions;
/**
* The array of filters registered with WordPress.
*
* @since 0.1.0
* @access protected
* @var array $filters The filters registered with WordPress to fire when wdl loads.
*/
protected $filters;
/**
* Initialize the collections used to maintain the actions and filters.
*
* @since 0.1.0
*/
public function __construct() {
$this->actions = array();
$this->filters = array();
}
/**
* Add a new action to the collection to be registered with WordPress.
*
* @since 0.1.0
* @param string $hook The name of the WordPress action that is being registered.
* @param object $component A reference to the instance of the object on which the action is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
*/
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* Add a new filter to the collection to be registered with WordPress.
*
* @since 0.1.0
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
*/
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* A utility function that is used to register the actions and hooks into a single
* collection.
*
* @since 0.1.0
* @access private
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the $callback.
* @return array The collection of actions and filters registered with WordPress.
*/
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
$hooks[] = array(
'hook' => $hook,
'component' => $component,
'callback' => $callback,
'priority' => $priority,
'accepted_args' => $accepted_args,
);
return $hooks;
}
/**
* Register the filters and actions with WordPress.
*
* @since 0.1.0
*/
public function run() {
foreach ( $this->filters as $hook ) {
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
foreach ( $this->actions as $hook ) {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
}
}
}

View file

@ -0,0 +1,178 @@
<?php
/**
* The core plugin class.
*
* This is used to define internationalization, admin-specific hooks, and
* public-facing site hooks.
*
* @link https://chykalophia.com/woocommerce-direct-links
* @since 0.1.0
* @package Woocommerce_Direct_Links
* @subpackage Woocommerce_Direct_Links/includes
* @author Joel Sanguenza <joel@chykalophia.com>,
* Lord Francis Navarro <francis@chykalophia.com>
*/
// If this file is called directly, abort.
if (!defined('ABSPATH')) {
die;
}
if (!class_exists('Cklph_Wdl')) {
/**
* Loads the dependencies, internationalization, and the loader class.
*/
class Cklph_Wdl
{
/**
* The loader that's responsible for maintaining and registering all the hooks
*
* @since 0.1.0
* @access protected
* @var Wdl_Loader $wdl_loader Maintains and registers all hooks for wdl.
*/
protected $wdl_loader;
/**
* The unique identifier of wdl.
*
* @since 0.1.0
* @access protected
* @var string $wdl_name The string used to uniquely identify wdl.
*/
protected $wdl_name;
/**
* The current version
*
* @since 0.1.0
* @access protected
* @var string $wdl_version The current version of the wdl.
*/
protected $wdl_version;
/**
* Define the core functionality of wdl.
*
* @since 0.1.0
*/
public function __construct()
{
if (defined('WDL_VERSION')) {
$this->wdl_version = WDL_VERSION;
} else {
$this->wdl_version = '0.1.0';
}
$this->wdl_name = 'woocommerce-direct-links';
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
}
/**
* Load the required dependencies for wdl
* Also Creates an instance of the loader which will be used to register the hooks.
*
* @since 0.1.0
* @access private
*/
private function load_dependencies()
{
require_once CKLPH_WDL_PATH . 'admin/partials/list-tables/class-cklph-wdl-list-table.php';
require_once CKLPH_WDL_PATH . 'admin/partials/class-cklph-wdl-wc-products.php';
require_once CKLPH_WDL_PATH . 'admin/partials/class-cklph-wdl-shortlinks.php';
require_once CKLPH_WDL_PATH . 'admin/partials/class-cklph-wdl-rest-api.php';
require_once CKLPH_WDL_PATH . 'includes/class-cklph-wdl-loader.php';
require_once CKLPH_WDL_PATH . 'includes/class-cklph-wdl-i18n.php';
require_once CKLPH_WDL_PATH . 'admin/class-cklph-wdl-admin.php';
$this->wdl_loader = new Cklph_Wdl_Loader();
}
/**
* Define the locale for wdl for internationalization.
*
* @since 0.1.0
* @access private
*/
private function set_locale()
{
$wdl_i18n = new Cklph_Wdl_I18n();
$this->wdl_loader->add_action('plugins_loaded', $wdl_i18n, 'load_plugin_textdomain');
}
/**
* Register all of the hooks related to the admin area functionality
* of wdl.
*
* @since 0.1.0
* @access private
*/
private function define_admin_hooks()
{
$wdl_admin = new Cklph_Wdl_Admin($this->get_plugin_name(), $this->get_version());
$this->wdl_loader->add_action('rest_api_init', $wdl_admin, 'cklph_wdl_rest_api');
$this->wdl_loader->add_action('admin_init', $wdl_admin, 'cklph_wdl_has_woocommerce');
$this->wdl_loader->add_action('admin_init', $wdl_admin, 'cklph_wdl_settings_init');
$this->wdl_loader->add_action('admin_menu', $wdl_admin, 'cklph_wdl_add_admin_pages');
$this->wdl_loader->add_action('admin_enqueue_scripts', $wdl_admin, 'cklph_wdl_enqueue_styles');
$this->wdl_loader->add_action('admin_enqueue_scripts', $wdl_admin, 'cklph_wdl_enqueue_scripts');
$this->wdl_loader->add_action('add_meta_boxes', $wdl_admin, 'cklph_wdl_add_meta_box');
$this->wdl_loader->add_filter('plugin_action_links_' . CKLPH_WDL_BASE, $wdl_admin, 'cklph_wdl_add_action_links');
$this->wdl_loader->add_filter('set-screen-option', $wdl_admin, 'cklph_wdl_set_pagination_option', 10, 3);
}
/**
* Run the wdl loader to execute all of the hooks with WordPress.
*
* @since 0.1.0
*/
public function run()
{
$this->wdl_loader->run();
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @since 0.1.0
* @return string The name of the plugin.
*/
public function get_plugin_name()
{
return $this->wdl_name;
}
/**
* The reference to the class that orchestrates the hooks with wdl.
*
* @since 0.1.0
* @return WDL_Loader Orchestrates the hooks wdl.
*/
public function get_loader()
{
return $this->wdl_loader;
}
/**
* Retrieve the version number of wdl.
*
* @since 0.1.0
* @return string The version number of wdl.
*/
public function get_version()
{
return $this->wdl_version;
}
}
}

1
includes/index.php Normal file
View file

@ -0,0 +1 @@
<?php // Silence is golden.