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

339
LICENSE.txt Normal file
View File

@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

24
README.txt Normal file
View File

@ -0,0 +1,24 @@
=== Chykalophia Woocommerce Direct Links ===
Contributors: Joel Sanguenza (joel@chykalophia.com), Lord Francis Navarro (francis@chykalophia.com)
Tags: Woocommerce, Chykalophia, Woocommerce Direct Links
Requires at least:
Tested up to:
Stable tag:
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
A plugin that displays the list of Woocommerce products their add-to-cart links which directly proceeds to checkout.
== Description ==
Woocommerce Direct Links is an extension plugin for the Woocommerce plugin which displays the list of Woocommerce products (simple and variable products) along with its add-to-cart links. These add-to-cart links automatically adds the product or product variation to the cart and redirects the user to the checkout page. You may choose from two (2) url shorteners (Tinyurl and Bitly) to shrink the links.
== Installation ==
1. Upload `cklph-woo-directlinks` to the `/wp-content/plugins/` directory. Or upload it through the admin dashboard.
2. Activate the plugin through the 'Plugins' menu in WordPress. Make sure that Woocommerce is already activated before activation this plugin.
== Frequently Asked Questions ==
== Screenshots ==
== Changelog ==

View File

@ -0,0 +1,884 @@
<?php
/**
* The admin-specific functionality of WDL.
*
* Defines the plugin name, version, enqueues the necessarry css and js files for the admin page,
* defines the admin page, submenu page, and the settings page.
*
* @package Woocommerce_Direct_Links
* @subpackage Woocommerce_Direct_Links/includes
* @author Joel Sanguenza <joel@chykalophia.com>,
* Lord Francis Navarro <francis@chykalophia.com>
* @link https://chykalophia.com/woocommerce-direct-links
* @since 0.1.0
*/
if ( ! class_exists( 'Cklph_Wdl_Admin' ) ) {
/**
* Plugin admin/settings class
*/
class Cklph_Wdl_Admin {
/**
* The ID of wdl.
*
* @since 0.1.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of wdl.
*
* @since 0.1.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Initialize the class and set its properties.
*
* @since 0.1.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the admin area.
*
* @since 0.1.0
*/
public function cklph_wdl_enqueue_styles() {
$screen = get_current_screen();
if ( 'toplevel_page_cklph-wdl-admin' === $screen->id ) {
wp_enqueue_style( $this->plugin_name, CKLPH_WDL_URL . 'admin/css/cklph-wdl-admin.css', array(), $this->version, 'all' );
}
if ( 'product' === $screen->id ) {
wp_enqueue_style( $this->plugin_name, CKLPH_WDL_URL . 'admin/css/cklph-wdl-metabox.css', array(), $this->version, 'all' );
}
if ( 'woocommerce-direct-links_page_cklph-wdl-settings' === $screen->id ) {
wp_enqueue_style( $this->plugin_name, CKLPH_WDL_URL . 'admin/css/cklph-wdl-settings.css', array(), $this->version, 'all' );
}
}
/**
* Register the JavaScript for the admin area.
*
* @since 0.1.0
*/
public function cklph_wdl_enqueue_scripts() {
$screen = get_current_screen();
if ( 'toplevel_page_cklph-wdl-admin' === $screen->id || 'product' === $screen->id ) {
wp_enqueue_script( $this->plugin_name, CKLPH_WDL_URL . 'admin/js/cklph-wdl-admin.js', array( 'jquery' ), $this->version, false ); // Load js scripts for admin and product pages.
// Localized scripts for wp rest api nonce for admin and product pages.
wp_localize_script(
$this->plugin_name,
'cklph_wdl',
array(
'product-joturl' => home_url( '/wp-json/cklph-wdl/v1/product-joturl/' ),
'product' => home_url( '/wp-json/cklph-wdl/v1/product/' ),
'nonce' => wp_create_nonce( 'wp_rest' ),
),
);
}
if ( 'woocommerce-direct-links_page_cklph-wdl-settings' === $screen->id ) {
wp_enqueue_script( $this->plugin_name, CKLPH_WDL_URL . 'admin/js/cklph-wdl-settings.js', array( 'jquery' ), $this->version, false ); // Load js scripts for settings page.
// Localized scripts for wp rest api nonce for settings page.
wp_localize_script(
$this->plugin_name,
'cklph_wdl',
array(
'shortlink' => home_url( '/wp-json/cklph-wdl/v1/shortlink/' ),
'product' => home_url( '/wp-json/cklph-wdl/v1/product/' ),
'tinyurl' => home_url( '/wp-json/cklph-wdl/v1/tinyurl/' ),
'yourls' => home_url( '/wp-json/cklph-wdl/v1/yourls/' ),
'joturl' => home_url( '/wp-json/cklph-wdl/v1/joturl/' ),
'bitly' => home_url( '/wp-json/cklph-wdl/v1/bitly/' ),
'nonce' => wp_create_nonce( 'wp_rest' ),
),
);
}
}
/**
* Validate if woocommerce is active
*
* @since 0.1.0
*/
public function cklph_wdl_has_woocommerce() {
if ( is_admin() && current_user_can( 'activate_plugins' ) && ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
add_action( 'admin_notices', array( $this, 'cklph_wdl_no_woocommerce_error' ) );
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
deactivate_plugins( CKLPH_WDL_BASE );
}
}
/**
* Error message if woocommerce is not installed and activated
*
* @since 0.1.0
*/
public function cklph_wdl_no_woocommerce_error() {
echo '<div class="notice notice-error settings-error is-dismissible">
<p><strong>' . esc_html__( 'Cannot activate WooCommerce Direct Links without WooCommerce installed and activated.', 'woocommerce-direct-links' ) . ' </strong></p>
</div>';
}
/**
* Adds the admin and settings pages
*
* @since 0.1.0
* @return void for admin page
*/
public function cklph_wdl_add_admin_pages() {
// If WooCommerce is activated run admin menu and submenu page.
if ( class_exists( 'woocommerce' ) ) {
$admin_page = add_menu_page(
__( 'Woocommerce Direct Links', 'woocommerce-direct-links' ),
__( 'Woocommerce Direct Links', 'woocommerce-direct-links' ),
'manage_options',
'cklph-wdl-admin',
array( $this, 'cklph_wdl_admin_page' ),
'dashicons-store',
110
);
$with_subpage = add_submenu_page(
'cklph-wdl-admin',
__( 'Woocommerce Direct Links', 'woocommerce-direct-links' ),
__( 'WDL Table', 'woocommerce-direct-links' ),
'manage_options',
'cklph-wdl-admin',
array( $this, 'cklph_wdl_admin_page' ),
);
add_submenu_page(
'cklph-wdl-admin',
__( 'Woocommerce Direct Links', 'woocommerce-direct-links' ),
__( 'Settings', 'woocommerce-direct-links' ),
'manage_options',
'cklph-wdl-settings',
array( $this, 'cklph_wdl_settings_page' )
);
add_action( "load-{$admin_page}", array( $this, 'cklph_wdl_screen_options' ) );
array_merge( array( $with_subpage, $admin_page ) );
}
}
/**
* Callback for admin page
*
* @since 0.1.0
* @return void callback path
*/
public function cklph_wdl_admin_page() {
include_once CKLPH_WDL_PATH . 'admin/partials/cklph-wdl-admin-page.php';
}
/**
* Callback for settings page
*
* @since 0.1.0
* @return void callback path
*/
public function cklph_wdl_settings_page() {
include_once CKLPH_WDL_PATH . 'admin/partials/cklph-wdl-settings-page.php';
}
/**
* Add meta box in WooCommerce products page
*
* @since 0.1.0
*/
public function cklph_wdl_add_meta_box() {
$product = wc_get_product( get_the_ID() );
$screen = get_current_screen();
if ( 'product' === $screen->id ) {
if ( $product->is_type( array( 'simple', 'variable', 'subscription' ) ) && 'publish' === $product->get_status() ) {
add_meta_box(
'cklph-wdl-product-meta-box',
__( 'WooCommerce Direct Links', 'woocommerce-direct-links' ),
array( $this, 'cklph_wdl_admin_page' ),
'product'
);
}
}
}
/**
* Screen options for admin page.
*
* @since 0.1.0
* @return void
*/
public function cklph_wdl_screen_options() {
$screen = get_current_screen();
if ( 'toplevel_page_cklph-wdl-admin' !== $screen->id || ! is_object( $screen ) ) {
return;
}
// Array for per page in screen-options.
$per_page_args = array(
'default' => 5,
'option' => 'cklph_wdl_per_page',
);
add_screen_option( 'per_page', $per_page_args );
new Cklph_Wdl_List_Table();
}
/**
* Rest Api initialize.
*
* @return void
*/
public function cklph_wdl_rest_api() {
if ( class_exists( 'Cklph_Wdl_Rest' ) ) {
$controller = new Cklph_Wdl_Rest();
$controller->cklph_wdl_rest_route();
}
}
/**
* Screen options for pagination on list table.
*
* @since 0.1.0
* @param bool|int $status Screen option value. Default false to skip.
* @param string $option The option name.
* @param int $value The number of rows to use.
* @return $value
*/
public function cklph_wdl_set_pagination_option( $status, $option, $value ) {
if ( 'cklph_wdl_per_page' === $option ) {
return $value;
}
}
/**
* Adding plugin links
*
* @since 0.1.0
* @param array $actions action_links array.
* @return $actions action links in plugin page.
*/
public function cklph_wdl_add_action_links( $actions ) {
$settings = array( '<a href="' . esc_url( admin_url( 'admin.php?page=cklph-wdl-settings' ) ) . '">Settings</a>' );
if ( class_exists( 'woocommerce' ) ) {
$actions = array_merge( $settings, $actions );
}
return $actions;
}
/**
* Initialize settings
*
* @since 0.1.0
* @return void for settings
*/
public function cklph_wdl_settings_init() {
// setup settings section.
add_settings_section(
'settings_section', // section id.
__( 'Settings', 'woocommerce-direct-link' ), // section title.
array( $this, 'cklph_wdl_settings' ), // callback.
'cklph-wdl-settings' // page.
);
// register radio field for URL Shortener.
register_setting(
'cklph-wdl-option-group',
'url_options',
array(
'type' => 'string',
'default' => 'none',
'sanitize_callback' => 'sanitize_text_field',
)
);
// add radio field for URL Shortener.
add_settings_field(
'url_options',
__( 'URL Shortener', 'woocommerce-direct-link' ),
array( $this, 'cklph_wdl_url_shortener' ),
'cklph-wdl-settings',
'settings_section',
array(
'label_for' => 'url_options',
'class' => 'plugin_row',
)
);
$this->cklph_wdl_bitly_option();
$this->cklph_wdl_yourls_option();
$this->cklph_wdl_joturl_option();
$this->cklph_wdl_tinyurl_option();
}
/**
* Add & register settings section & field for Tinyurl.
*
* @return void
*/
public function cklph_wdl_tinyurl_option() {
// setup tinyurl settings section.
add_settings_section(
'tinyurl_section', // section id.
__( 'TinyURL', 'woocommerce-direct-link' ), // section title.
array( $this, 'cklph_wdl_settings_tinyurl' ), // callback.
'cklph-wdl-tinyurl-settings' // page.
);
// register field for tinyurl domain.
register_setting(
'cklph-wdl-tinyurl-group',
'tinyurl_domain',
array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
)
);
// register field for tinyurl access token.
register_setting(
'cklph-wdl-tinyurl-group',
'tinyurl_access_token_options',
array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
)
);
// add input field for tinyurl domain.
add_settings_field(
'tinyurl_domain',
__( 'TinyURL Domain', 'woocommerce-direct-link' ),
array( $this, 'cklph_wdl_tinyurl_domain' ),
'cklph-wdl-tinyurl-settings',
'tinyurl_section',
array(
'label_for' => 'tinyurl_domain',
'class' => 'plugin_row',
)
);
// add input field for tinyurl access token.
add_settings_field(
'tinyurl_access_token_options',
__( 'TinyURL Access Token', 'woocommerce-direct-link' ),
array( $this, 'cklph_wdl_tinyurl_api_key' ),
'cklph-wdl-tinyurl-settings',
'tinyurl_section',
array(
'label_for' => 'tinyurl_access_token_options',
'class' => 'plugin_row',
)
);
}
/**
* Add & register settings section & field for bitly.
*
* @return void
*/
public function cklph_wdl_bitly_option() {
// setup bitly settings section.
add_settings_section(
'bitly_section', // section id.
__( 'Bitly', 'woocommerce-direct-link' ), // section title.
array( $this, 'cklph_wdl_settings_bitly' ), // callback.
'cklph-wdl-bitly-settings' // page.
);
// register field for Bitly access token.
register_setting(
'cklph-wdl-bitly-group',
'bitly_access_token_options',
array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
)
);
// add input field for Bitly access token.
add_settings_field(
'bitly_access_token_options',
__( 'Bitly Access Token', 'woocommerce-direct-link' ),
array( $this, 'cklph_wdl_bitly_api_key' ),
'cklph-wdl-bitly-settings',
'bitly_section',
array(
'label_for' => 'bitly_access_token_options',
'class' => 'plugin_row',
)
);
}
/**
* Add & register settings section & field for yourls.
*
* @return void
*/
public function cklph_wdl_yourls_option() {
// setup yourls settings section.
add_settings_section(
'yourls_section', // section id.
__( 'YoURLS', 'woocommerce-direct-link' ), // section title.
array( $this, 'cklph_wdl_settings_yourls' ), // callback.
'cklph-wdl-yourls-settings' // page.
);
// register field for YoURLS signature.
register_setting(
'cklph-wdl-yourls-group',
'yourls_signature',
array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
)
);
// register field for YoURLS domain.
register_setting(
'cklph-wdl-yourls-group',
'yourls_domain',
array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
)
);
// add input field for YoURLS domain.
add_settings_field(
'yourls_domain',
__( 'YoURLS Site', 'woocommerce-direct-link' ),
array( $this, 'cklph_wdl_yourls_domain' ),
'cklph-wdl-yourls-settings',
'yourls_section',
array(
'label_for' => 'yourls_domain',
'class' => 'plugin_row',
)
);
// add input field for YoURLS Signature.
add_settings_field(
'yourls_signature',
__( 'YoURLS Signature', 'woocommerce-direct-link' ),
array( $this, 'cklph_wdl_yourls_signature' ),
'cklph-wdl-yourls-settings',
'yourls_section',
array(
'label_for' => 'yourls_signature',
'class' => 'plugin_row',
)
);
}
/**
* Add & register settings section & field for JotURL.
*
* @return void
*/
public function cklph_wdl_joturl_option() {
// setup tinyurl settings section.
add_settings_section(
'joturl_section', // section id.
__( 'JotURL', 'woocommerce-direct-link' ), // section title.
array( $this, 'cklph_wdl_settings_joturl' ), // callback.
'cklph-wdl-joturl-settings' // page.
);
// register field for joturl domain.
register_setting(
'cklph-wdl-joturl-group',
'joturl_public',
array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
)
);
// register field for joturl access token.
register_setting(
'cklph-wdl-joturl-group',
'joturl_private',
array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
)
);
// add input field for joturl domain.
add_settings_field(
'joturl_public',
__( 'JotURL Public Key', 'woocommerce-direct-link' ),
array( $this, 'cklph_wdl_joturl_public' ),
'cklph-wdl-joturl-settings',
'joturl_section',
array(
'label_for' => 'joturl_public',
'class' => 'plugin_row',
)
);
// add input field for joturl access token.
add_settings_field(
'joturl_private',
__( 'JotURL Private Key', 'woocommerce-direct-link' ),
array( $this, 'cklph_wdl_joturl_private' ),
'cklph-wdl-joturl-settings',
'joturl_section',
array(
'label_for' => 'joturl_private',
'class' => 'plugin_row',
)
);
}
/**
* Settings general callback
*
* @since 0.1.0
* @param int $args settings callback id.
*/
public function cklph_wdl_settings( $args ) {
return sprintf(
'<p id="$1$s">%2$s</p>',
esc_attr( $args['id'] ),
esc_html_e( 'Choose URL Shortener.', 'woocommerce-direct-link' )
);
}
/**
* Settings tinyurl callback
*
* @since 0.1.0
* @param int $args settings callback id.
*/
public function cklph_wdl_settings_tinyurl( $args ) {
return sprintf(
'<p id="$1$s">%2$s</p>',
esc_attr( $args['id'] ),
esc_html_e( 'Please enter a valid TinyURL API Key or use automatic tinyurl shortener.', 'woocommerce-direct-link' )
);
}
/**
* Settings bitly callback
*
* @since 0.1.0
* @param int $args settings callback id.
*/
public function cklph_wdl_settings_bitly( $args ) {
return sprintf(
'<p id="$1$s">%2$s</p>',
esc_attr( $args['id'] ),
esc_html_e( 'Please enter a valid Bitly API Key.', 'woocommerce-direct-link' )
);
}
/**
* Settings yourls callback
*
* @since 0.1.0
* @param int $args settings callback id.
*/
public function cklph_wdl_settings_yourls( $args ) {
return sprintf(
'<p id="$1$s">%2$s</p>',
esc_attr( $args['id'] ),
esc_html_e( 'Please enter a valid YoURLS Site & Signature.', 'woocommerce-direct-link' )
);
}
/**
* Settings joturl callback
*
* @since 0.1.0
* @param int $args settings callback id.
*/
public function cklph_wdl_settings_joturl( $args ) {
return sprintf(
'<p id="$1$s">%2$s</p>',
esc_attr( $args['id'] ),
esc_html_e( 'Please enter a valid JotURL Public Key & Private Key.', 'woocommerce-direct-link' )
);
}
/**
* Tinyurl access token callback
*
* @return void
*/
public function cklph_wdl_tinyurl_api_key() {
$access_token = get_option( 'tinyurl_access_token_options' );
$api_value = isset( $access_token ) ? esc_attr( $access_token ) : '';
echo sprintf(
'<input type="text" placeholder="TinyURL API Here" id="tinyurl_access_token_options" name="tinyurl_access_token_options" value="%1$s" />',
esc_attr( $api_value )
);
}
/**
* Tinyurl Domain callback.
*
* @return void
*/
public function cklph_wdl_tinyurl_domain() {
$tinyurl_domain = get_option( 'tinyurl_domain' );
$domain_value = isset( $tinyurl_domain ) ? esc_attr( $tinyurl_domain ) : '';
echo sprintf(
'<input type="text" placeholder="e.g tiny.one" id="tinyurl_domain" name="tinyurl_domain" value="%1$s" />',
esc_attr( $domain_value )
);
}
/**
* Bitly access token callback
*
* @since 0.1.0
*/
public function cklph_wdl_bitly_api_key() {
$access_token = get_option( 'bitly_access_token_options' );
$api_value = isset( $access_token ) ? esc_attr( $access_token ) : '';
echo sprintf(
'<input type="text" placeholder="Bitly API Key Here" id="bitly_access_token_options" name="bitly_access_token_options" value="%1$s" />',
esc_attr( $api_value )
);
}
/**
* YoURLS signature callback.
*
* @return void
*/
public function cklph_wdl_yourls_signature() {
$yourls_signature = get_option( 'yourls_signature' );
$signature_value = isset( $yourls_signature ) ? esc_attr( $yourls_signature ) : '';
echo sprintf(
'<input type="text" placeholder="YoURLS API Key Here" id="yourls_signature" name="yourls_signature" value="%1$s" />',
esc_attr( $signature_value )
);
}
/**
* YoURLS domain callback
*
* @return void
*/
public function cklph_wdl_yourls_domain() {
$yourls_domain = get_option( 'yourls_domain' );
$domain_value = isset( $yourls_domain ) ? esc_attr( $yourls_domain ) : '';
echo sprintf(
'<input type="text" placeholder="e.g yourls.org" id="yourls_domain" name="yourls_domain" value="%1$s" />',
esc_attr( $domain_value )
);
}
/**
* JotURL public key callback.
*
* @return void
*/
public function cklph_wdl_joturl_public() {
$joturl_public_key = get_option( 'joturl_public' );
$public_key_value = isset( $joturl_public_key ) ? esc_attr( $joturl_public_key ) : '';
echo sprintf(
'<input type="text" placeholder="JotURL Public API Key" id="joturl_public_key" name="joturl_public_key" value="%1$s" />',
esc_attr( $public_key_value )
);
}
/**
* JotURL private key callback.
*
* @return void
*/
public function cklph_wdl_joturl_private() {
$joturl_private_key = get_option( 'joturl_private' );
$private_key_value = isset( $joturl_private_key ) ? esc_attr( $joturl_private_key ) : '';
echo sprintf(
'<input type="text" placeholder="JotURL Private API Key" id="joturl_private_key" name="joturl_private_key" value="%1$s" />',
esc_attr( $private_key_value )
);
}
/**
* Url shortener option template in settings page.
*
* @since 0.1.0
* @return void html elements in settings page.
*/
public function cklph_wdl_url_shortener() {
$this->cklph_wdl_tinyurl_shortener();
$this->cklph_wdl_bitly_shortener();
$this->cklph_wdl_yourls_shortener();
$this->cklph_wdl_joturl_shortener();
}
/**
* Tinyurl shortener option template in settings page.
*
* @since 0.1.0
* @return void html elements for tinyurl in settings page.
*/
public function cklph_wdl_tinyurl_shortener() {
$url_option = get_option( 'url_options' );
$setup_text = esc_html__( 'Setup', 'woocommerce-direct-links' );
$tinyurl_img = CKLPH_WDL_URL . 'admin/img/tinyurl.svg';
$tinyurl_text = esc_html__( 'TinyURL', 'woocommerce-direct-link' );
$active_tinyurl = ( 'tinyurl' === $url_option ) ? esc_html__( 'Deactivate', 'woocommerce-direct-links' ) : esc_html__( 'Activate', 'woocommerce-direct-links' );
// Echo html tags for tinyurl.
echo sprintf(
'<div class="shortener">
<img class="logo" src="%1$s" alt="tinyurl">
<h3>%2$s</h3>
<div class="box">
<button class="button button-primary" name="setup_btn" type="button" id="tinyurl_setup_btn" onclick="cklph_wdl_shortlink_setup(\'tinyurl\')" >%3$s</button>
</div>
<div class="box">
<button class="button button-primary" name="activate_btn" type="button" id="tinyurl_activate_btn" onclick="cklph_wdl_activate_tinyurl()" ><span id="tinyurl-span" class="cklph-wdl-btn-text">%4$s</span></button>
</div>
</div>',
esc_attr( $tinyurl_img ),
esc_attr( $tinyurl_text ),
esc_attr( $setup_text ),
esc_attr( $active_tinyurl ),
);
}
/**
* Bitly shortener option template in settings page.
*
* @since 0.1.0
* @return void html elements for Bitly in settings page.
*/
public function cklph_wdl_bitly_shortener() {
$setup_text = esc_html__( 'Setup', 'woocommerce-direct-links' );
$url_option = get_option( 'url_options' );
$bitly_img = CKLPH_WDL_URL . 'admin/img/bitly.svg';
$bitly_text = esc_html__( 'Bitly', 'woocommerce-direct-link' );
$active_bitly = ( 'bitly' === $url_option ) ? esc_html__( 'Deactivate', 'woocommerce-direct-links' ) : esc_html__( 'Activate', 'woocommerce-direct-links' );
// Echo html tags for bitly.
echo sprintf(
'<div class="shortener">
<img class="logo" src="%1$s" alt="bitly">
<h3>%2$s</h3>
<div class="box">
<button class="button button-primary" name="setup_btn" type="button" id="bitly_setup_btn" onclick="cklph_wdl_shortlink_setup(\'bitly\')" >%3$s</button>
</div>
<div class="box">
<button class="button button-primary" name="activate_btn" type="button" id="bitly_activate_btn" onclick="cklph_wdl_activate_bitly()" ><span id="bitly-span" class="cklph-wdl-btn-text">%4$s</span></button>
</div>
</div>',
esc_attr( $bitly_img ),
esc_attr( $bitly_text ),
esc_attr( $setup_text ),
esc_attr( $active_bitly ),
);
}
/**
* Yourls shortener option template in settings page.
*
* @since 0.1.0
* @return void html elements for yourls in settings page.
*/
public function cklph_wdl_yourls_shortener() {
$setup_text = esc_html__( 'Setup', 'woocommerce-direct-links' );
$url_option = get_option( 'url_options' );
$yourls_img = CKLPH_WDL_URL . 'admin/img/yourls.svg';
$yourls_text = esc_html__( 'YoURLS', 'woocommerce-direct-link' );
$active_yourls = ( 'yourls' === $url_option ) ? esc_html__( 'Deactivate', 'woocommerce-direct-links' ) : esc_html__( 'Activate', 'woocommerce-direct-links' );
// Echo html tags for yourls.
echo sprintf(
'<div class="shortener">
<img class="logo" src="%1$s" alt="yourls">
<h3>%2$s</h3>
<div class="box">
<button class="button button-primary" name="setup_btn" type="button" id="yourls_setup_btn" onclick="cklph_wdl_shortlink_setup(\'yourls\')" >%3$s</button>
</div>
<div class="box">
<button class="button button-primary" name="activate_btn" type="button" id="yourls_activate_btn" onclick="cklph_wdl_activate_yourls()" ><span id="yourls-span" class="cklph-wdl-btn-text">%4$s</span></button>
</div>
</div>',
esc_attr( $yourls_img ),
esc_attr( $yourls_text ),
esc_attr( $setup_text ),
esc_attr( $active_yourls ),
);
}
/**
* Joturl shortener option template in settings page.
*
* @since 0.1.0
* @return void html elements for joturl in settings page.
*/
public function cklph_wdl_joturl_shortener() {
$setup_text = esc_html__( 'Setup', 'woocommerce-direct-links' );
$url_option = get_option( 'url_options' );
$joturl_img = CKLPH_WDL_URL . 'admin/img/joturl.png';
$joturl_text = esc_html__( 'JotURL', 'woocommerce-direct-link' );
$active_joturl = ( 'joturl' === $url_option ) ? esc_html__( 'Deactivate', 'woocommerce-direct-links' ) : esc_html__( 'Activate', 'woocommerce-direct-links' );
// Echo html tags for joturl.
echo sprintf(
'<div class="shortener">
<img class="logo" src="%1$s" alt="joturl">
<h3>%2$s</h3>
<div class="box">
<button class="button button-primary" name="setup_btn" type="button" id="yourls_setup_btn" onclick="cklph_wdl_shortlink_setup(\'joturl\')" >%3$s</button>
</div>
<div class="box">
<button class="button button-primary" name="activate_btn" type="button" id="joturl_activate_btn" onclick="cklph_wdl_activate_joturl()" ><span id="joturl-span" class="cklph-wdl-btn-text">%4$s</span></button>
</div>
</div>',
esc_attr( $joturl_img ),
esc_attr( $joturl_text ),
esc_attr( $setup_text ),
esc_attr( $active_joturl ),
);
}
}
}

View File

@ -0,0 +1,177 @@
/**
* All of the CSS for your admin-specific functionality should be
* included in this file.
*/
/* tooltip position for copy button */
.tooltip {
position: relative;
display: inline-block;
}
/* tooltip text for copy button */
.tooltip .tooltiptext {
visibility: hidden;
width: 140px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 150%;
left: 50%;
margin-left: -75px;
opacity: 0;
transition: opacity 0.3s;
}
/* tooltip text for copy button "Link has been copied" */
.tooltip .tooltiptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
/* tooltip text for copy button "Copy" */
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
/* for IE & MS Edge */
#id:hover {
cursor: pointer;
}
/* class for span in refresh button */
.cklph-wdl-btn-text {
transition: all 0.2s;
}
/* class for button in refresh button */
.button-primary {
position: relative;
}
/* class for loading when refresh button unused. */
.cklph-wdl-loading .cklph-wdl-btn-text {
visibility: hidden;
opacity: 0;
}
/* class for loading when refresh button is click. */
.cklph-wdl-loading::after {
content: "";
position: absolute;
width: 10px;
height: 10px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
border: 4px solid transparent;
border-top-color: #fff;
border-radius: 50%;
animation: cklph-wdl-btn-loading 1s ease infinite;
}
.cklph-wdl-input {
width: 90%;
}
/* loading animation */
@keyframes cklph-wdl-btn-loading {
from {
transform: rotate(0turn);
}
to {
transform: rotate(1turn);
}
}
/* image for list table */
.wc-image {
display: block;
position: relative;
text-indent: -9999px;
margin: 0 auto;
height: 1em;
width: 1em;
}
/* image for list table show icon */
table.wp-list-table span.wc-image::before {
font-family: Dashicons;
position: absolute;
font-weight: 400;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
margin: 0;
text-indent: 0;
top: 0;
left: 0;
width: 100%;
height: 100%;
content: "\f128";
}
/* admin list table css */
.wp-list-table .column-thumb { width: 5%; text-align: center; }
.wp-list-table .column-post_title { width: 25%; }
.wp-list-table .column-sku { width: 8%; }
.wp-list-table .column-attrib { width: 8%; }
.wp-list-table .column-category { width: 8%; }
.wp-list-table .column-guid { width: 25%; }
.wp-list-table .column-copy { width: 8%; }
.wp-list-table .column-refresh { width: 8%; }
@media screen and (max-width: 1480px) {
/* admin list table css */
.wp-list-table .column-thumb { width: 2%; text-align: center; }
.wp-list-table .column-post_title { width: 12%; }
.wp-list-table .column-sku { width: 5%; }
.wp-list-table .column-attrib { width: 5%; }
.wp-list-table .column-category { width: 5%; }
.wp-list-table .column-guid { width: 12%; }
.wp-list-table .column-copy { width: 6%; }
.wp-list-table .column-refresh { width: 7%; }
}
@media screen and (max-width: 1024px) {
/* admin list table css */
.wp-list-table .column-post_title { width: 10%; }
.wp-list-table .column-guid { width: 10%; }
.wp-list-table .column-copy { width: 8%; }
.wp-list-table .column-refresh { width: 9%; }
}
@media screen and (max-width: 782px) {
.wp-list-table td.column-primary {
padding-right: 1%;
width: 100%;
}
.wp-list-table .column-thumb {
display: none;
text-align: left;
}
.wp-list-table .column-thumb::before {
visibility: hidden;
}
}

View File

@ -0,0 +1,128 @@
/**
* All of the CSS for metabox in product page functionality should be
* included in this file.
*/
/* tooltip position for copy button */
.tooltip {
position: relative;
display: inline-block;
}
/* tooltip text for copy button */
.tooltip .tooltiptext {
visibility: hidden;
width: 140px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 150%;
left: 50%;
margin-left: -75px;
opacity: 0;
transition: opacity 0.3s;
}
/* tooltip text for copy button "Link has been copied" */
.tooltip .tooltiptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
/* tooltip text for copy button "Copy" */
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
/* for IE & MS Edge */
#id:hover {
cursor: pointer;
}
/* class for span in refresh button */
.cklph-wdl-btn-text {
transition: all 0.2s;
}
/* class for button in refresh button */
.button-primary {
position: relative;
}
/* class for loading when refresh button unused. */
.cklph-wdl-loading .cklph-wdl-btn-text {
visibility: hidden;
opacity: 0;
}
/* class for loading when refresh button is click. */
.cklph-wdl-loading::after {
content: "";
position: absolute;
width: 10px;
height: 10px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
border: 4px solid transparent;
border-top-color: #fff;
border-radius: 50%;
animation: cklph-wdl-btn-loading 1s ease infinite;
}
/* loading animation */
@keyframes cklph-wdl-btn-loading {
from {
transform: rotate(0turn);
}
to {
transform: rotate(1turn);
}
}
.cklph-wdl-input {
width: 90%;
}
/* metabox list table css */
.wp-list-table .column-thumb { width: 3% !important; }
.wp-list-table .column-post_title { width: 22%; }
.wp-list-table .column-sku { width: 10%; }
.wp-list-table .column-attrib { width: 10%; }
.wp-list-table .column-guid {width: 20%; }
.wp-list-table .column-copy { width: 8%; }
.wp-list-table .column-refresh { width: 13%; }
@media screen and (max-width: 1300px) {
.wp-list-table .column-thumb { display: none; }
.wp-list-table .column-post_title { width: 10%; }
.wp-list-table .column-sku { display: none; }
.wp-list-table .column-attrib { display: none; }
.wp-list-table .column-guid {width: 9%; }
.wp-list-table .column-copy { width: 5%; }
.wp-list-table .column-refresh { width: 6%; }
}
@media screen and (max-width: 782px) {
span.ID {
padding: 8px;
}
.cklph-wdl-input {
width: 90%;
}
}

View File

@ -0,0 +1,113 @@
.tab-content {
position: relative;
}
.tab-content > .tab-pane {
float: left;
width: 100%;
display: none;
}
.tab-content > .tab-pane.active {
display: block;
padding: 10px;
}
.shortener {
width: 20%;
display: inline-block;
border: 1px solid;
border-radius: 25px;
padding: 10px;
margin: 10px;
text-align: center;
align-items: center;
}
.box {
margin: 5px;
display: inline-block;
}
.logo {
margin: 10px;
height: 50px;
width: auto;
}
.cklph-wdl-btn-text {
transition: all 0.2s;
}
.button-primary {
position: relative;
}
.cklph-wdl-loading .cklph-wdl-btn-text {
visibility: hidden;
opacity: 0;
}
.cklph-wdl-loading::after {
content: "";
position: absolute;
width: 10px;
height: 10px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
border: 4px solid transparent;
border-top-color: #fff;
border-radius: 50%;
animation: cklph-wdl-btn-loading 1s ease infinite;
}
.cklph-wdl-bulk {
position: absolute;
bottom: 80%;
left: 84%;
}
@media screen and (max-width: 1366px) {
.shortener {
width: 40%;
}
.cklph-wdl-bulk {
bottom: 90%;
left: 78%;
}
.logo {
height: 40px;
}
}
@media screen and (max-width: 800px) {
.cklph-wdl-bulk {
left: 68%;
}
}
@media screen and (max-width: 480px) {
.shortener {
width: 90%;
}
.cklph-wdl-bulk {
bottom: 92%;
left: 65%;
}
}
@keyframes cklph-wdl-btn-loading {
from {
transform: rotate(0turn);
}
to {
transform: rotate(1turn);
}
}

1
admin/img/bitly.svg Normal file
View File

@ -0,0 +1 @@
<svg height="2500" viewBox=".82 .51 958.8 958.8" width="2499" xmlns="http://www.w3.org/2000/svg"><path d="m959.62 484.03c0 225.24-150.78 358.42-256.43 418.45-69.42 39.44-117.21 56.83-179.43 56.83-144.54 0-204.91-88.4-204.91-165.37 3.98-279.03-3.28-387.62-3.57-395.1-.38-9.73-.74-24.96-10.18-25.97-5.74-.62-9.44 1.14-16.04 9.38-9.89 13.19-29.85 18.41-42 11.36-14.67-8.52-17.41-27.33-9.98-44.64 20.6-46.15 53.63-66.57 98.15-65.93 76.91 1.1 98.98 51.52 98.98 114.51-1.14 63.62-1.71 112.47-1.71 146.53 27.2-22.25 67.18-46.12 133.95-46.12 92.23 0 171.73 67.96 171.73 193.41 0 73.7-19.24 111.55-19.38 111.91 93.32-81.42 145.02-209.07 145.02-314.79 0-173.03-134.42-377.17-385.79-377.17-206.51 0-389.84 173.73-389.84 380.2 0 114.96 59.77 230.05 146.23 306.07 22.28 19.59 23.27 47.55 11.28 59.16-14.21 13.78-39.02 15.25-59.84-.82-108.14-83.45-185.04-222.35-185.04-366.12 0-277.27 213.05-489.3 477.21-489.3 253.66 0 481.59 202.08 481.59 483.52zm-332.47 221.04c0-77.23-39.3-104.21-98.3-92.41-47.43 9.49-95.49 58.93-100.69 127.65-.86 11.34-1.15 30.13-.25 47.77 2.4 47.03 41.65 64.33 95.46 63.38 89.29-1.56 103.78-94.2 103.78-146.39z" fill="#ee6123"/></svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
admin/img/joturl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

22
admin/img/tinyurl.svg Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="180" height="50" version="1.2" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<metadata>
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<rect width="180" height="50" fill="#17527d"/>
<g transform="matrix(.99605 0 0 1 .0045556 0)" fill="#fff" stroke-width=".9779">
<path d="m14.269 37.814h-5.577q-0.6541 0-0.96393-0.288-0.27541-0.324-0.27541-1.008v-17.676h-5.0607q-0.6541 0-0.96393-0.288-0.27541-0.324-0.27541-1.008v-4.356q0-0.684 0.27541-0.972 0.30984-0.324 0.96393-0.324h18.177q0.6541 0 0.92951 0.324 0.30984 0.288 0.30984 0.972v4.356q0 0.684-0.30984 1.008-0.27541 0.288-0.92951 0.288h-5.0607v17.676q0 0.684-0.30984 1.008-0.27541 0.288-0.92951 0.288z" color="#ffffff"/>
<path d="m27.902 37.814q-0.6541 0-0.96393-0.288-0.27541-0.324-0.27541-1.008v-4.284q0-0.684 0.27541-0.972 0.30984-0.324 0.96393-0.324h3.4082v-12.096h-3.4082q-0.6541 0-0.96393-0.288-0.27541-0.324-0.27541-1.008v-4.356q0-0.684 0.27541-0.972 0.30984-0.324 0.96393-0.324h14.666q0.6541 0 0.92951 0.324 0.30984 0.288 0.30984 0.972v4.356q0 0.684-0.30984 1.008-0.27541 0.288-0.92951 0.288h-3.3393v12.096h3.3393q0.6541 0 0.92951 0.324 0.30984 0.288 0.30984 0.972v4.284q0 0.684-0.30984 1.008-0.27541 0.288-0.92951 0.288z" color="#ffffff"/>
<path d="m56.51 37.814h-5.1639q-0.6541 0-0.96394-0.288-0.27541-0.324-0.27541-1.008v-23.328q0-0.684 0.27541-0.972 0.30984-0.324 0.96394-0.324h3.5803q0.6541 0 1.1016 0.216 0.48197 0.216 0.92951 0.756l6.6787 7.992v-7.668q0-0.684 0.27541-0.972 0.30984-0.324 0.96394-0.324h5.1639q0.6541 0 0.92951 0.324 0.30984 0.288 0.30984 0.972v23.328q0 0.684-0.30984 1.008-0.27541 0.288-0.92951 0.288h-5.1639q-0.6541 0-0.96394-0.288-0.27541-0.324-0.27541-1.008v-4.428l-5.8869-7.452v11.88q0 0.684-0.30984 1.008-0.27541 0.288-0.92951 0.288z" color="#ffffff"/>
<path d="m90.661 37.814h-5.577q-0.6541 0-0.96393-0.288-0.27541-0.324-0.27541-1.008v-4.608l-5.2672-7.38q-0.7918-1.116-1.0672-1.944-0.24098-0.828-0.24098-2.484v-6.912q0-0.684 0.27541-0.972 0.30984-0.324 0.96393-0.324h5.3016q0.6541 0 0.92951 0.324 0.30984 0.288 0.30984 0.972v5.904q0 0.36 0.03442 0.756 0.03443 0.396 0.27541 0.756l1.5836 2.592q0.17213 0.324 0.34426 0.468 0.20656 0.144 0.48197 0.144h0.34426q0.27541 0 0.44754-0.144 0.20656-0.144 0.37869-0.468l1.5836-2.592q0.24098-0.36 0.27541-0.756 0.03442-0.396 0.03442-0.756v-5.904q0-0.684 0.27541-0.972 0.30984-0.324 0.96393-0.324h5.1295q0.65409 0 0.92951 0.324 0.30984 0.288 0.30984 0.972v6.912q0 1.656-0.27542 2.484-0.27541 0.828-1.0328 1.944l-5.2328 7.416v4.572q0 0.684-0.30984 1.008-0.27541 0.288-0.92951 0.288z" color="#ffffff"/>
<path d="m125.53 31.01q0 1.656-0.48197 3.024-0.44754 1.332-1.6525 2.304-1.1705 0.936-3.2361 1.476-2.0656 0.54-5.2672 0.54t-5.2672-0.54q-2.0656-0.54-3.2705-1.476-1.1705-0.972-1.6525-2.304-0.44754-1.368-0.44754-3.024v-17.82q0-0.684 0.27541-0.972 0.30984-0.324 0.96394-0.324h5.4049q0.65411 0 0.92951 0.324 0.30984 0.288 0.30984 0.972v16.416q0 0.72 0.51639 1.224 0.5164 0.468 2.3066 0.468 1.8246 0 2.341-0.468 0.5164-0.504 0.5164-1.224v-16.416q0-0.684 0.2754-0.972 0.30984-0.324 0.96394-0.324h5.2328q0.65409 0 0.9295 0.324 0.30984 0.288 0.30984 0.972z" color="#ffffff"/>
<path d="m139.96 18.374v4.608h2.582q0.89508 0 1.2049-0.468 0.30983-0.504 0.30983-1.224v-1.224q0-0.72-0.30983-1.188-0.30984-0.504-1.2049-0.504zm-1.2393 19.44h-5.3016q-0.6541 0-0.96393-0.288-0.27541-0.324-0.27541-1.008v-23.328q0-0.684 0.27541-0.972 0.30983-0.324 0.96393-0.324h11.464q3.8557 0 5.3016 1.692 1.4803 1.656 1.4803 4.32v1.656q0 1.512-0.44754 2.592-0.41312 1.044-1.4803 1.512 1.859 0.216 2.9951 1.584 1.1705 1.368 1.1705 3.636v7.632q0 0.684-0.30983 1.008-0.27541 0.288-0.92951 0.288h-5.3361q-0.6541 0-0.96394-0.288-0.2754-0.324-0.2754-1.008v-5.508q0-0.792-0.30984-1.152-0.27542-0.396-0.99837-0.396h-4.8197v7.056q0 0.684-0.30983 1.008-0.27541 0.288-0.9295 0.288z" color="#ffffff"/>
<path d="m178.59 37.814h-17.523q-0.6541 0-0.96394-0.288-0.2754-0.324-0.2754-1.008v-23.328q0-0.684 0.2754-0.972 0.30984-0.324 0.96394-0.324h5.3361q0.6541 0 0.92951 0.324 0.30984 0.288 0.30984 0.972v17.82h4.7164v-5.832q0-0.684 0.2754-0.972 0.30984-0.324 0.96393-0.324h4.9918q0.65411 0 0.92952 0.324 0.30983 0.288 0.30983 0.972v11.34q0 0.684-0.30983 1.008-0.27541 0.288-0.92952 0.288z" color="#ffffff"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.4 KiB

1
admin/img/yourls.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 23 KiB

1
admin/index.php Normal file
View File

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

186
admin/js/cklph-wdl-admin.js Normal file
View File

@ -0,0 +1,186 @@
/**
* The JavaScript code for the admin
*
*/
// Copy the checkout url of product.
function cklph_wdl_copyurl( id ){
copyText = document.getElementById(`cklph-wdl-url-${id}`);
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
var tooltip = document.getElementById(`myTooltip-${id}`);
tooltip.innerHTML = "Link has been copied";
}
// Copy tooltip.
function cklph_wdl_out( id ) {
var tooltip = document.getElementById(`myTooltip-${id}`);
tooltip.innerHTML = "Copy";
}
// Refresh checkout links.
function cklph_wdl_rest( id ) {
var cklphWdlBtn = document.getElementById(`cklph-wdl-btn-${id}`);
var cklphWdlHidden = document.getElementById('cklph-wdl-hidden');
var countClick = 0;
cklphWdlHidden.value = 'clicked';
cklph_wdl_refresh(id);
cklphWdlBtn.onclick = () => {
if('created' === cklphWdlHidden.value) {
cklph_wdl_refresh(id);
cklphWdlHidden.value = 'exists';
countClick += 2;
} else {
countClick += 1;
if(1 === countClick) {
cklph_wdl_force_joturl_refresh(id);
cklphWdlHidden.value = 'exists';
} else {
cklph_wdl_refresh(id);
cklphWdlHidden.value = 'exists';
}
}
}
}
async function cklph_wdl_refresh(id) {
var cklphWdlHidden = document.getElementById('cklph-wdl-hidden');
var replyDiv = document.getElementById("cklph-wdl-reply");
var cklphWdlBtn = document.getElementById(`cklph-wdl-btn-${id}`);
var cklphWdlInput = document.getElementById(`cklph-wdl-url-${id}`);
var ckplhWdlReply = (!document.getElementById('cklph-message')) ? document.createElement('div') : document.getElementById('cklph-message');
var dismissButton = document.createElement('button');
ckplhWdlReply.setAttribute('id', 'cklph-message');
dismissButton.setAttribute('type', 'button');
dismissButton.setAttribute('onclick', 'this.closest(\'div\').remove()');
dismissButton.className = 'notice-dismiss';
replyDiv.appendChild(ckplhWdlReply);
cklphWdlBtn.classList.toggle("cklph-wdl-loading");
cklphWdlBtn.style.pointerEvents = "none";
// run wp rest api to convert links and return success or error.
try {
try {
const response = await fetch(`/wp-json/cklph-wdl/v1/product/${id}/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': cklph_wdl.nonce,
}
});
const urlResponse = await response.json();
cklphWdlInput.value = urlResponse[0];
switch (urlResponse[1]) {
case 200:
ckplhWdlReply.className = "notice notice-success settings-error is-dismissible";
if('clicked' === cklphWdlHidden.value) {
ckplhWdlReply.innerHTML = `<p><strong>Link already exists. Please press Refresh Link again to force refresh shortlink. ${urlResponse[0]}</strong></p>`;
} else {
ckplhWdlReply.innerHTML = `<p><strong>Link already refreshed. ${urlResponse[0]}</strong></p>`;
}
break;
case 201:
ckplhWdlReply.className = "notice notice-success settings-error is-dismissible";
ckplhWdlReply.innerHTML = `<p><strong>Link successfully created. ${urlResponse[0]}</strong></p>`;
cklphWdlHidden.value = 'created';
break;
case '401-bitly':
ckplhWdlReply.className = "notice notice-warning settings-error is-dismissible";
ckplhWdlReply.innerHTML = '<p><strong>Please enter a valid Bitly API Key.</strong></p>';
break;
case '401-yourls':
ckplhWdlReply.className = "notice notice-warning settings-error is-dismissible";
ckplhWdlReply.innerHTML = '<p><strong>Please enter a valid YoURLS Site & Signature.</strong></p>';
break;
case '401-joturl':
ckplhWdlReply.className = "notice notice-warning settings-error is-dismissible";
ckplhWdlReply.innerHTML = '<p><strong>Please enter a valid JotURL Public & Private API Key.</strong></p>';
break;
default:
ckplhWdlReply.className = "notice notice-error settings-error is-dismissible";
ckplhWdlReply.innerHTML = `<p><strong>${urlResponse[1]}</strong></p>`;
break;
}
} catch (error) {
ckplhWdlReply.className = "notice notice-error settings-error is-dismissible";
ckplhWdlReply.innerHTML = `<p><strong>An unknown error occured. ${error}</strong></p>`;
}
} finally {
ckplhWdlReply.appendChild(dismissButton);
cklphWdlBtn.classList.toggle("cklph-wdl-loading");
cklphWdlBtn.style.pointerEvents = "auto";
}
}
async function cklph_wdl_force_joturl_refresh(id) {
var cklphWdlHidden = document.getElementById('cklph-wdl-hidden');
var replyDiv = document.getElementById("cklph-wdl-reply");
var cklphWdlBtn = document.getElementById(`cklph-wdl-btn-${id}`);
var cklphWdlInput = document.getElementById(`cklph-wdl-url-${id}`);
var ckplhWdlReply = (!document.getElementById('cklph-message')) ? document.createElement('div') : document.getElementById('cklph-message');
var dismissButton = document.createElement('button');
dismissButton.setAttribute('type', 'button');
dismissButton.setAttribute('onclick', 'this.closest(\'div\').remove()');
dismissButton.className = 'notice-dismiss';
replyDiv.appendChild(ckplhWdlReply);
cklphWdlBtn.classList.toggle("cklph-wdl-loading");
cklphWdlBtn.style.pointerEvents = "none";
// run wp rest api to convert links and return success or error.
try {
try {
const response = await fetch(`/wp-json/cklph-wdl/v1/product-joturl/${id}/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': cklph_wdl.nonce,
}
});
const urlResponse = await response.json();
cklphWdlInput.value = urlResponse[0];
switch (urlResponse[1]) {
case 200:
ckplhWdlReply.className = "notice notice-success settings-error is-dismissible";
ckplhWdlReply.innerHTML = `<p><strong>Link successfully refreshed. ${urlResponse[0]}</strong></p>`;
break;
case 201:
ckplhWdlReply.className = "notice notice-success settings-error is-dismissible";
ckplhWdlReply.innerHTML = `<p><strong>Link successfully created. ${urlResponse[0]}</strong></p>`;
cklphWdlHidden.value = 'created';
break;
case '401-bitly':
ckplhWdlReply.className = "notice notice-warning settings-error is-dismissible";
ckplhWdlReply.innerHTML = '<p><strong>Please enter a valid Bitly API Key.</strong></p>';
break;
case '401-yourls':
ckplhWdlReply.className = "notice notice-warning settings-error is-dismissible";
ckplhWdlReply.innerHTML = '<p><strong>Please enter a valid YoURLS Site & Signature.</strong></p>';
break;
case '401-joturl':
ckplhWdlReply.className = "notice notice-warning settings-error is-dismissible";
ckplhWdlReply.innerHTML = '<p><strong>Please enter a valid JotURL Public & Private API Key.</strong></p>';
break;
default:
ckplhWdlReply.className = "notice notice-error settings-error is-dismissible";
ckplhWdlReply.innerHTML = `<p><strong>${urlResponse[1]}</strong></p>`;
break;
}
} catch (error) {
ckplhWdlReply.className = "notice notice-error settings-error is-dismissible";
ckplhWdlReply.innerHTML = `<p><strong>An unknown error occured. ${error}</strong></p>`;
}
} finally {
ckplhWdlReply.appendChild(dismissButton);
cklphWdlBtn.classList.toggle("cklph-wdl-loading");
cklphWdlBtn.style.pointerEvents = "auto";
}
}

View File

@ -0,0 +1,566 @@
/**
* The JavaScript code for the settings
*
*/
// show/hide setup for shortlink.
function cklph_wdl_shortlink_setup(shortlink) {
var tabBitly = document.getElementById('tab-bitly');
var tabYourls = document.getElementById('tab-yourls');
var tabjoturl = document.getElementById('tab-joturl');
var tabTinyurl = document.getElementById('tab-tinyurl');
switch (shortlink) {
case 'tinyurl':
tabTinyurl.classList.toggle('active');
tabBitly.classList.remove('active');
tabYourls.classList.remove('active');
tabjoturl.classList.remove('active');
break;
case 'bitly':
tabBitly.classList.toggle('active');
tabYourls.classList.remove('active');
tabTinyurl.classList.remove('active');
tabjoturl.classList.remove('active');
break;
case 'yourls':
tabYourls.classList.toggle('active');
tabBitly.classList.remove('active');
tabjoturl.classList.remove('active');
tabTinyurl.classList.remove('active');
break;
case 'joturl':
tabjoturl.classList.toggle('active');
tabYourls.classList.remove('active');
tabTinyurl.classList.remove('active');
tabBitly.classList.remove('active');
break;
default:
break;
}
}
// Bulk refresh checkout links.
function cklph_wdl_bulk_rest() {
var ckplhWdlReply = document.getElementById('cklph-wdl-reply');
var cklphWdlBtn = document.getElementById('cklph-wdl-bulk-btn');
var replyDiv = (!document.getElementById('cklph-message')) ? document.createElement('div') : document.getElementById('cklph-message');
var dismissButton = document.createElement('button');
replyDiv.setAttribute('id', 'cklph-message');
dismissButton.setAttribute('type', 'button');
dismissButton.setAttribute('onclick', 'this.closest(\'div\').remove()');
dismissButton.className = 'notice-dismiss';
ckplhWdlReply.appendChild(replyDiv);
cklphWdlBtn.classList.toggle("cklph-wdl-loading");
cklphWdlBtn.style.pointerEvents = "none";
replyDiv.className = "notice notice-warning settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>Refreshing shortlinks please wait!</strong></p>';
fetch('/wp-json/cklph-wdl/v1/product/bulk', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': cklph_wdl.nonce,
}
}).then(response => {
return response.json();
}).then(urlResponse => {
switch(urlResponse) {
case 200:
replyDiv.className = "notice notice-success settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>Shortlinks Refreshed.</strong></p>';
break;
case '401-bitly':
replyDiv.className = "notice notice-warning settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>Please enter a valid Bitly API Key.</strong></p>';
break;
case '401-yourls':
replyDiv.className = "notice notice-warning settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>Please enter a valid YoURLS Site & Signature.</strong></p>';
break;
default:
replyDiv.className = "notice notice-warning settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>No URL Shortener is activated. Please set and activate a shortener to refresh all links.</strong></p>';
break;
}
}).catch(error => {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>An unknown error occured. ${error}</strong></p>`;
}).finally(() => {
replyDiv.appendChild(dismissButton);
cklphWdlBtn.classList.toggle("cklph-wdl-loading");
cklphWdlBtn.style.pointerEvents = "auto";
});
}
/**
* This Section is for tinyurl setup and activate.
*
* Activate tinyurl in settings page.
*/
function cklph_wdl_activate_tinyurl() {
var loadBitly = document.getElementById('bitly-span');
var loadYourls = document.getElementById('yourls-span');
var loadJoturl = document.getElementById('joturl-span');
var loadTinyurl = document.getElementById('tinyurl-span');
var ckplhWdlReply = document.getElementById('cklph-wdl-reply');
var onclickTinyurl = document.getElementById('tinyurl_activate_btn');
var tinyurlApiKey = document.getElementById('tinyurl_access_token_options');
var replyDiv = (!document.getElementById('cklph-message')) ? document.createElement('div') : document.getElementById('cklph-message');
var dismissButton = document.createElement('button');
replyDiv.setAttribute('id', 'cklph-message');
dismissButton.setAttribute('type', 'button');
dismissButton.setAttribute('onclick', 'this.closest(\'div\').remove()');
dismissButton.className = 'notice-dismiss';
ckplhWdlReply.appendChild(replyDiv);
onclickTinyurl.classList.toggle("cklph-wdl-loading");
onclickTinyurl.style.pointerEvents = "none";
fetch(`/wp-json/cklph-wdl/v1/shortlink/tinyurl/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': cklph_wdl.nonce,
}
}).then(response => {
return response.json();
}).then(shortlinkResponse => {
replyDiv.className = "notice notice-success settings-error is-dismissible";
if ('tinyurl' === shortlinkResponse) {
loadBitly.innerHTML = 'Activate';
loadYourls.innerHTML = 'Activate';
loadJoturl.innerHTML = 'Activate';
loadTinyurl.innerHTML = 'Deactivate';
if (tinyurlApiKey.value) {
replyDiv.innerHTML = '<p><strong>TinyURL successfully activated using API Key.</strong></p>';
return;
}
replyDiv.innerHTML = '<p><strong>TinyURL successfully activated without using API Key.</strong></p>';
} else {
loadTinyurl.innerHTML = 'Activate';
replyDiv.innerHTML = '<p><strong>TinyURL successfully deactivated.</strong></p>';
}
}).catch(error => {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>An unknown error occured. ${error}</strong></p>`;
}).finally(() => {
replyDiv.appendChild(dismissButton);
onclickTinyurl.classList.toggle("cklph-wdl-loading");
onclickTinyurl.style.pointerEvents = "auto";
});
}
// Save settings for tinyurl setup.
function cklph_wdl_setup_tinyurl() {
var ckplhWdlReply = document.getElementById('cklph-wdl-reply');
var tinyurlSaveBtn = document.getElementById('tinyurl-save-btn');
var tinyurlDomain = document.getElementById('tinyurl_domain');
var tinyurlApiKey = document.getElementById('tinyurl_access_token_options');
var replyDiv = (!document.getElementById('cklph-message')) ? document.createElement('div') : document.getElementById('cklph-message');
var dismissButton = document.createElement('button');
replyDiv.setAttribute('id', 'cklph-message');
dismissButton.setAttribute('type', 'button');
dismissButton.setAttribute('onclick', 'this.closest(\'div\').remove()');
dismissButton.className = 'notice-dismiss';
ckplhWdlReply.appendChild(replyDiv);
tinyurlSaveBtn.classList.toggle("cklph-wdl-loading");
tinyurlSaveBtn.style.pointerEvents = "none";
fetch(`/wp-json/cklph-wdl/v1/tinyurl/?domain=${tinyurlDomain.value}&apikey=${tinyurlApiKey.value}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': cklph_wdl.nonce,
}
}).then(response => {
return response.json();
}).then(tinyurlResponse => {
if (200 === tinyurlResponse) {
if (tinyurlApiKey.value) {
replyDiv.className = "notice notice-success settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>Settings Saved.</strong></p>`;
return;
}
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>Unable to save TinyURL settings because Access token is empty.</strong></p>`;
} else if ('401-tinyurl' === tinyurlResponse) {
replyDiv.className = "notice notice-warning settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>Please enter a valid TinyURL API Key.</strong></p>';
tinyurlDomain.value = '';
} else if ('422-tinyurl' === tinyurlResponse) {
replyDiv.className = "notice notice-warning settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>Unable to save TinyURL Domain. An Error has occured. Error code: 422 : Domain not found</strong></p>';
tinyurlDomain.value = '';
} else {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>Unable to save TinyURL settings. ${tinyurlResponse}</strong></p>`;
tinyurlDomain.value = '';
tinyurlApiKey.value = '';
}
}).catch(error => {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>An unknown error occured. ${error}</strong></p>`;
}).finally(() => {
replyDiv.appendChild(dismissButton);
tinyurlSaveBtn.classList.toggle("cklph-wdl-loading");
tinyurlSaveBtn.style.pointerEvents = "auto";
});
}
/**
* This Section is for bitly setup and activate.
*
* Activate bitly in settings page.
*/
function cklph_wdl_activate_bitly() {
var loadBitly = document.getElementById('bitly-span');
var loadYourls = document.getElementById('yourls-span');
var loadJoturl = document.getElementById('joturl-span');
var loadTinyurl = document.getElementById('tinyurl-span');
var ckplhWdlReply = document.getElementById('cklph-wdl-reply');
var onclickBitly = document.getElementById('bitly_activate_btn');
var replyDiv = (!document.getElementById('cklph-message')) ? document.createElement('div') : document.getElementById('cklph-message');
var dismissButton = document.createElement('button');
replyDiv.setAttribute('id', 'cklph-message');
dismissButton.setAttribute('type', 'button');
dismissButton.setAttribute('onclick', 'this.closest(\'div\').remove()');
dismissButton.className = 'notice-dismiss';
ckplhWdlReply.appendChild(replyDiv);
onclickBitly.classList.toggle("cklph-wdl-loading");
onclickBitly.style.pointerEvents = "none";
fetch(`/wp-json/cklph-wdl/v1/shortlink/bitly/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': cklph_wdl.nonce,
}
}).then(response => {
return response.json();
}).then(shortlinkResponse => {
replyDiv.className = "notice notice-success settings-error is-dismissible";
if ('bitly' === shortlinkResponse) {
loadTinyurl.innerHTML = 'Activate';
loadYourls.innerHTML = 'Activate';
loadJoturl.innerHTML = 'Activate';
loadBitly.innerHTML = 'Deactivate';
replyDiv.innerHTML = '<p><strong>Bitly successfully activated</strong></p>';
} else if ('401-bitly' === shortlinkResponse) {
replyDiv.className = "notice notice-warning settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>Please enter a valid Bitly API Key to activate Bitly shortener.</strong></p>';
} else {
loadBitly.innerHTML = 'Activate';
replyDiv.innerHTML = '<p><strong>Bitly successfully deactivated.</strong></p>';
}
}).catch(error => {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>An unknown error occured. ${error}</strong></p>`;
}).finally(() => {
replyDiv.appendChild(dismissButton);
onclickBitly.classList.toggle("cklph-wdl-loading");
onclickBitly.style.pointerEvents = "auto";
});
}
// Save settings for bitly setup.
function cklph_wdl_setup_bitly() {
var ckplhWdlReply = document.getElementById('cklph-wdl-reply');
var bitlySaveBtn = document.getElementById('bitly-save-btn');
var bitlyApiKey = document.getElementById('bitly_access_token_options');
var loadBitly = document.getElementById('bitly-span');
var replyDiv = (!document.getElementById('cklph-message')) ? document.createElement('div') : document.getElementById('cklph-message');
var dismissButton = document.createElement('button');
replyDiv.setAttribute('id', 'cklph-message');
dismissButton.setAttribute('type', 'button');
dismissButton.setAttribute('onclick', 'this.closest(\'div\').remove()');
dismissButton.className = 'notice-dismiss';
ckplhWdlReply.appendChild(replyDiv);
bitlySaveBtn.classList.toggle("cklph-wdl-loading");
bitlySaveBtn.style.pointerEvents = "none";
fetch(`/wp-json/cklph-wdl/v1/bitly/?apikey=${bitlyApiKey.value}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': cklph_wdl.nonce,
}
}).then(response => {
return response.json();
}).then(bitlyResponse => {
if (200 === bitlyResponse) {
replyDiv.className = "notice notice-success settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>Settings Saved.</strong></p>`;
} else if ('401-bitly' === bitlyResponse) {
replyDiv.className = "notice notice-warning settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>Please enter a valid Bitly API Key.</strong></p>';
loadBitly.innerHTML = 'Activate';
} else {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>Unable to save Bitly settings. ${bitlyResponse}</strong></p>`;
loadBitly.innerHTML = 'Activate';
bitlyApiKey.value = '';
}
}).catch(error => {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>An unknown error occured. ${error}</strong></p>`;
}).finally(() => {
replyDiv.appendChild(dismissButton);
bitlySaveBtn.classList.toggle("cklph-wdl-loading");
bitlySaveBtn.style.pointerEvents = "auto";
});
}
/**
* This Section is for yourls setup and activate.
*
* Activate yourls in settings page.
*/
function cklph_wdl_activate_yourls() {
var loadBitly = document.getElementById('bitly-span');
var loadYourls = document.getElementById('yourls-span');
var loadJoturl = document.getElementById('joturl-span');
var loadTinyurl = document.getElementById('tinyurl-span');
var onclickYourls = document.getElementById('yourls_activate_btn');
var ckplhWdlReply = document.getElementById('cklph-wdl-reply');
var replyDiv = (!document.getElementById('cklph-message')) ? document.createElement('div') : document.getElementById('cklph-message');
var dismissButton = document.createElement('button');
replyDiv.setAttribute('id', 'cklph-message');
dismissButton.setAttribute('type', 'button');
dismissButton.setAttribute('onclick', 'this.closest(\'div\').remove()');
dismissButton.className = 'notice-dismiss';
ckplhWdlReply.appendChild(replyDiv);
onclickYourls.classList.toggle("cklph-wdl-loading");
onclickYourls.style.pointerEvents = "none";
fetch(`/wp-json/cklph-wdl/v1/shortlink/yourls/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': cklph_wdl.nonce,
}
}).then(response => {
return response.json();
}).then(shortlinkResponse => {
replyDiv.className = "notice notice-success settings-error is-dismissible";
if ('yourls' === shortlinkResponse) {
loadBitly.innerHTML = 'Activate';
loadJoturl.innerHTML = 'Activate';
loadTinyurl.innerHTML = 'Activate';
loadYourls.innerHTML = 'Deactivate';
replyDiv.innerHTML = '<p><strong>YoURLS successfully activated</strong></p>';
} else if ('401-yourls' === shortlinkResponse) {
replyDiv.className = "notice notice-warning settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>Please enter a valid YoURLS Site & Signature to activate YoURLS shortener.</strong></p>';
} else {
loadYourls.innerHTML = 'Activate';
replyDiv.innerHTML = '<p><strong>YoURLS successfully deactivated.</strong></p>';
}
}).catch(error => {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>An unknown error occured. ${error}</strong></p>`;
}).finally(() => {
replyDiv.appendChild(dismissButton);
onclickYourls.classList.toggle("cklph-wdl-loading");
onclickYourls.style.pointerEvents = "auto";
});
}
// Save settings for yourls setup.
function cklph_wdl_setup_yourls() {
var ckplhWdlReply = document.getElementById('cklph-wdl-reply');
var yourlsSaveBtn = document.getElementById('yourls-save-btn');
var yourlsDomain = document.getElementById('yourls_domain');
var yourlsApiKey = document.getElementById('yourls_signature');
var loadYourls = document.getElementById('yourls-span');
var replyDiv = (!document.getElementById('cklph-message')) ? document.createElement('div') : document.getElementById('cklph-message');
var dismissButton = document.createElement('button');
replyDiv.setAttribute('id', 'cklph-message');
dismissButton.setAttribute('type', 'button');
dismissButton.setAttribute('onclick', 'this.closest(\'div\').remove()');
dismissButton.className = 'notice-dismiss';
ckplhWdlReply.appendChild(replyDiv);
yourlsSaveBtn.classList.toggle("cklph-wdl-loading");
yourlsSaveBtn.style.pointerEvents = "none";
fetch(`/wp-json/cklph-wdl/v1/yourls/?domain=${yourlsDomain.value}&apikey=${yourlsApiKey.value}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': cklph_wdl.nonce,
}
}).then(response => {
return response.json();
}).then(yourlsResponse => {
if ('401-yourls' === yourlsResponse) {
replyDiv.className = "notice notice-warning settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>Please enter a valid YoURLS Site & Signature.</strong></p>';
} else if (200 !== yourlsResponse) {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>Unable to save YoURLS settings. ${yourlsResponse}</strong></p>`;
yourlsDomain.value = '';
yourlsApiKey.value = '';
loadYourls.innerHTML = 'Activate';
} else {
replyDiv.className = "notice notice-success settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>Settings Saved.</strong></p>`;
}
}).catch(error => {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>An unknown error occured. ${error}</strong></p>`;
}).finally(() => {
replyDiv.appendChild(dismissButton);
yourlsSaveBtn.classList.toggle("cklph-wdl-loading");
yourlsSaveBtn.style.pointerEvents = "auto";
});
}
/**
* This Section is for JotURL setup and activate.
*
* Activate JotURL in settings page.
*/
function cklph_wdl_activate_joturl() {
var loadBitly = document.getElementById('bitly-span');
var loadYourls = document.getElementById('yourls-span');
var loadJoturl = document.getElementById('joturl-span');
var loadTinyurl = document.getElementById('tinyurl-span');
var onclickJoturl = document.getElementById('joturl_activate_btn');
var ckplhWdlReply = document.getElementById('cklph-wdl-reply');
var replyDiv = (!document.getElementById('cklph-message')) ? document.createElement('div') : document.getElementById('cklph-message');
var dismissButton = document.createElement('button');
replyDiv.setAttribute('id', 'cklph-message');
dismissButton.setAttribute('type', 'button');
dismissButton.setAttribute('onclick', 'this.closest(\'div\').remove()');
dismissButton.className = 'notice-dismiss';
ckplhWdlReply.appendChild(replyDiv);
onclickJoturl.classList.toggle("cklph-wdl-loading");
onclickJoturl.style.pointerEvents = "none";
fetch(`/wp-json/cklph-wdl/v1/shortlink/joturl/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': cklph_wdl.nonce,
}
}).then(response => {
return response.json();
}).then(shortlinkResponse => {
replyDiv.className = "notice notice-success settings-error is-dismissible";
if ('joturl' === shortlinkResponse) {
loadBitly.innerHTML = 'Activate';
loadYourls.innerHTML = 'Activate';
loadTinyurl.innerHTML = 'Activate';
loadJoturl.innerHTML = 'Deactivate';
replyDiv.innerHTML = '<p><strong>JotURL successfully activated</strong></p>';
} else if ('401-joturl' === shortlinkResponse) {
replyDiv.className = "notice notice-warning settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>Please enter a valid Public & Private API Key to activate JotURL shortener.</strong></p>';
} else {
loadJoturl.innerHTML = 'Activate';
replyDiv.innerHTML = '<p><strong>JotURL successfully deactivated.</strong></p>';
}
}).catch(error => {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>An unknown error occured. ${error}</strong></p>`;
}).finally(() => {
replyDiv.appendChild(dismissButton);
onclickJoturl.classList.toggle("cklph-wdl-loading");
onclickJoturl.style.pointerEvents = "auto";
});
}
function cklph_wdl_setup_joturl() {
var loadJoturl = document.getElementById('joturl-span');
var ckplhWdlReply = document.getElementById('cklph-wdl-reply');
var joturlSaveBtn = document.getElementById('joturl-save-btn');
var joturlPublic = document.getElementById('joturl_public_key');
var joturlPrivate = document.getElementById('joturl_private_key');
var replyDiv = (!document.getElementById('cklph-message')) ? document.createElement('div') : document.getElementById('cklph-message');
var dismissButton = document.createElement('button');
replyDiv.setAttribute('id', 'cklph-message');
dismissButton.setAttribute('type', 'button');
dismissButton.setAttribute('onclick', 'this.closest(\'div\').remove()');
dismissButton.className = 'notice-dismiss';
ckplhWdlReply.appendChild(replyDiv);
joturlSaveBtn.classList.toggle("cklph-wdl-loading");
joturlSaveBtn.style.pointerEvents = "none";
fetch(`/wp-json/cklph-wdl/v1/joturl/?public=${joturlPublic.value}&private=${joturlPrivate.value}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': cklph_wdl.nonce,
}
}).then(response => {
return response.json();
}).then(joturlResponse => {
if ('401-joturl' === joturlResponse) {
replyDiv.className = "notice notice-warning settings-error is-dismissible";
replyDiv.innerHTML = '<p><strong>Please enter a valid JotURL Public & Private API Key.</strong></p>';
} else if (200 !== joturlResponse) {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>Unable to save JotURL settings. ${joturlResponse}</strong></p>`;
joturlPublic.value = '';
joturlPrivate.value = '';
loadJoturl.innerHTML = 'Activate';
} else {
replyDiv.className = "notice notice-success settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>Settings Saved.</strong></p>`;
}
}).catch(error => {
replyDiv.className = "notice notice-error settings-error is-dismissible";
replyDiv.innerHTML = `<p><strong>An unknown error occured. ${error}</strong></p>`;
}).finally(() => {
replyDiv.appendChild(dismissButton);
joturlSaveBtn.classList.toggle("cklph-wdl-loading");
joturlSaveBtn.style.pointerEvents = "auto";
});
}
jQuery( function( $ ) {
var short_link = $(".shortener");
if ( short_link.length ) {
short_link.each(function() {
var get_active_box = $(this).find('.cklph-wdl-btn-text').html();
if (get_active_box == 'Deactivate') {
// add a class to active shortlink method
$(this).addClass('active-shortener');
// add a css to active shortlink method
$(this).css('background-color','#d3d3d3');
$(this).find("[name='activate_btn']").css('background-color','#218838');
$(this).find("[name='activate_btn']").css('border-color','#1e7e34');
}
});
}
});

View File

@ -0,0 +1,33 @@
<?php
/**
* Provide a admin page view for the plugin
*
* This file is used to markup the admin-facing aspects of the plugin.
*
* @link https://chykalophia.com/woocommerce-direct-links
* @since 0.1.0
*
* @package Woocommerce_Direct_Links
* @subpackage Woocommerce_Direct_Links/admin/partials
*/
if ( ! defined( 'ABSPATH' ) ) {
exit();
}
?>
<!-- Display Page for the WordPress Direct Link Admin Page -->
<div class="wrap">
<h1>
<?php
echo esc_html( get_admin_page_title() );
?>
</h1>
<input type="hidden" id="cklph-wdl-hidden">
<div id="cklph-wdl-reply" class=""></div>
<?php
$wdl_table = new Cklph_Wdl_List_Table();
$wdl_table->prepare_items();
$wdl_table->search_box( __( 'Search Products', 'woocommerce-direct-links' ), 'search' );
$wdl_table->display();

View File

@ -0,0 +1,105 @@
<?php
/**
* Provide a settings page view for the plugin
*
* This file is used to markup the admin-facing aspects of the plugin.
*
* @link https://chykalophia.com/woocommerce-direct-links
* @since 0.1.0
*
* @package Woocommerce_Direct_Links
* @subpackage Woocommerce_Direct_Links/admin/partials
*/
if ( ! defined( 'ABSPATH' ) ) {
exit();
}
?>
<div class="wrap">
<h1>
<?php
settings_errors( 'urlshortener_messages' );
echo esc_html( get_admin_page_title() );
?>
</h1>
<div id="cklph-wdl-reply" class=""></div>
<div class="tab-content">
<!-- Bulk Refresh Button -->
<button class="button button-primary cklph-wdl-bulk" type="button" id="cklph-wdl-bulk-btn" onclick="cklph_wdl_bulk_rest()" >
<span class="cklph-wdl-btn-text"><?php esc_html_e( 'Refresh All Links', 'woocommerce-direct-links' ); ?></span>
</button>
<?php
// setting field.
settings_fields( 'cklph-wdl-option-group' );
// output settings section.
do_settings_sections( 'cklph-wdl-settings' );
?>
<div id="tab-tinyurl" class="tab-pane">
<?php
// tinyurl setting field.
settings_fields( 'cklph-wdl-tinyurl-group' );
// output tinyurl settings section.
do_settings_sections( 'cklph-wdl-tinyurl-settings' );
?>
<button class="button button-primary" type="button" id="tinyurl-save-btn" onclick="cklph_wdl_setup_tinyurl()" >
<span class="cklph-wdl-btn-text">
<?php esc_html_e( 'Save Settings', 'woocommerce-direct-links' ); ?>
</span>
</button>
</div>
<div id="tab-bitly" class="tab-pane ">
<?php
// setting field.
settings_fields( 'cklph-wdl-bitly-group' );
// output settings section.
do_settings_sections( 'cklph-wdl-bitly-settings' );
?>
<button class="button button-primary" type="button" id="bitly-save-btn" onclick="cklph_wdl_setup_bitly()" >
<span class="cklph-wdl-btn-text">
<?php esc_html_e( 'Save Settings', 'woocommerce-direct-links' ); ?>
</span>
</button>
</div>
<div id="tab-yourls" class="tab-pane">
<?php
// setting field.
settings_fields( 'cklph-wdl-yourls-group' );
// output settings section.
do_settings_sections( 'cklph-wdl-yourls-settings' );
?>
<button class="button button-primary" type="button" id="yourls-save-btn" onclick="cklph_wdl_setup_yourls()" >
<span class="cklph-wdl-btn-text">
<?php esc_html_e( 'Save Settings', 'woocommerce-direct-links' ); ?>
</span>
</button>
</div>
<div id="tab-joturl" class="tab-pane">
<?php
// setting field.
settings_fields( 'cklph-wdl-joturl-group' );
// output settings section.
do_settings_sections( 'cklph-wdl-joturl-settings' );
?>
<button class="button button-primary" type="button" id="joturl-save-btn" onclick="cklph_wdl_setup_joturl()" >
<span class="cklph-wdl-btn-text">
<?php esc_html_e( 'Save Settings', 'woocommerce-direct-links' ); ?>
</span>
</button>
</div>
</div>
</div>

View File

@ -0,0 +1,409 @@
<?php
/**
* The list-table class that defines the product details and its add to cart url
*
* Get the product name, sku, thumbnail, and category of a woocommerce product and its checkout
* link.
*
* @link https://chykalophia.com/woocommerce-direct-links
* @since 0.1.0
* @package Woocommerce_Direct_Links
* @subpackage Woocommerce_Direct_Links/admin/partials/list-table
*/
if ( ! defined( 'ABSPATH' ) ) {
exit();
}
if ( ! class_exists( 'Cklph_Wdl_Rest' ) ) {
/**
* Rest Api for WDL Plugin.
*/
class Cklph_Wdl_Rest extends WP_REST_Controller {
/**
* Register rest route of the plugin.
*
* @return void
*/
public function cklph_wdl_rest_route() {
// rest route for individual shortlink request.
register_rest_route(
'cklph-wdl/v1',
'/product/(?P<id>\d+)',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'cklph_wdl_refresh' ),
'permission_callback' => array( $this, 'permission_check' ),
)
);
// rest route for individual force refresh request for joturl.
register_rest_route(
'cklph-wdl/v1',
'/product-joturl/(?P<id>\d+)',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'cklph_wdl_force_joturl' ),
'permission_callback' => array( $this, 'permission_check' ),
)
);
// rest route for bulk refresh request.
register_rest_route(
'cklph-wdl/v1',
'/product/bulk',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'cklph_wdl_bulk_refresh' ),
'permission_callback' => array( $this, 'permission_check' ),
)
);
// rest route for shortlink provider activate/deactivate.
register_rest_route(
'cklph-wdl/v1',
'/shortlink/(?P<shortlink>[a-zA-Z0-9-]+)',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'cklph_wdl_activate' ),
'permission_callback' => array( $this, 'permission_check' ),
)
);
// rest route for tinyurl setup.
register_rest_route(
'cklph-wdl/v1',
'/tinyurl',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'cklph_wdl_tinyurl_settings' ),
'permission_callback' => array( $this, 'permission_check' ),
'args' => array(
'domain' => array( 'validate_callback' => array( $this, 'validate_string_callback' ) ),
'apikey' => array( 'validate_callback' => array( $this, 'validate_string_callback' ) ),
),
)
);
// rest route for bitly setup.
register_rest_route(
'cklph-wdl/v1',
'/bitly',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'cklph_wdl_bitly_settings' ),
'permission_callback' => array( $this, 'permission_check' ),
'args' => array(
'apikey' => array( 'validate_callback' => array( $this, 'validate_string_callback' ) ),
),
)
);
// rest route for yourls setup.
register_rest_route(
'cklph-wdl/v1',
'/yourls',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'cklph_wdl_yourls_settings' ),
'permission_callback' => array( $this, 'permission_check' ),
'args' => array(
'domain' => array( 'validate_callback' => array( $this, 'validate_string_callback' ) ),
'apikey' => array( 'validate_callback' => array( $this, 'validate_string_callback' ) ),
),
)
);
// rest route for yourls setup.
register_rest_route(
'cklph-wdl/v1',
'/joturl',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'cklph_wdl_joturl_settings' ),
'permission_callback' => array( $this, 'permission_check' ),
'args' => array(
'public' => array( 'validate_callback' => array( $this, 'validate_string_callback' ) ),
'private' => array( 'validate_callback' => array( $this, 'validate_string_callback' ) ),
),
)
);
}
/**
* Validate if callback is string.
*
* @param string $param value of args.
* @param string $request request.
* @param string $key key.
* @return string $param
*/
public function validate_string_callback( $param, $request, $key ) {
return is_string( $param );
}
/**
* Check if a given request has access to data.
*
* @param mixed $request full data of the request.
* @return WP_Error|bool
*/
public function permission_check( $request ) {
return current_user_can( 'manage_options' );
}
/**
* Save setting setup for bitly.
*
* @param string $request api key for bitly.
* @return $result success || error.
*/
public function cklph_wdl_bitly_settings( $request ) {
$access_token = $request['apikey'];
$wc_product = new Cklph_Wdl_Wc_Products();
$product = $wc_product->get_single_wc_product_id();
update_option( 'bitly_access_token_options', $access_token );
$rest_url = $this->cklph_wdl_check_rest( $product, 'bitly' );
if ( ! is_numeric( $rest_url ) ) {
update_option( 'url_options', 'none' );
update_option( 'bitly_access_token_options', '' );
return new WP_REST_Response( $rest_url );
}
$bitly_apikey = get_option( 'bitly_access_token_options' );
$response = new WP_REST_Response( 200 );
return $response;
}
/**
* Save setting setup for tinyurl.
*
* @param string $request type, domain & apikey for tinyurl.
* @return $result success || error.
*/
public function cklph_wdl_tinyurl_settings( $request ) {
$tinyurl_domain = $request['domain'];
$tinyurl_apikey = $request['apikey'];
$wc_product = new Cklph_Wdl_Wc_Products();
$product = $wc_product->get_single_wc_product_id();
update_option( 'tinyurl_access_token_options', $tinyurl_apikey );
update_option( 'tinyurl_domain', $tinyurl_domain );
$rest_url = $this->cklph_wdl_check_rest( $product, 'tinyurl' );
if ( ! is_numeric( $rest_url ) ) {
update_option( 'tinyurl_domain', '' );
return new WP_REST_Response( $rest_url );
}
$response = new WP_REST_Response( 200 );
return $response;
}
/**
* Save setting setup for yourls.
*
* @param string $request site & api key for yourls.
* @return $result success || error.
*/
public function cklph_wdl_yourls_settings( $request ) {
$yourls_domain = $request['domain'];
$yourls_apikey = $request['apikey'];
$wc_product = new Cklph_Wdl_Wc_Products();
$product = $wc_product->get_single_wc_product_id();
update_option( 'yourls_signature', $yourls_apikey );
update_option( 'yourls_domain', $yourls_domain );
$rest_url = $this->cklph_wdl_check_rest( $product, 'yourls' );
if ( ! is_numeric( $rest_url ) ) {
update_option( 'url_options', 'none' );
update_option( 'yourls_domain', '' );
update_option( 'yourls_signature', '' );
return new WP_REST_Response( $rest_url );
}
$response = new WP_REST_Response( 200 );
return $response;
}
/**
* Save setting setup for joturl.
*
* @param string $request site & api key for yourls.
* @return $result success || error.
*/
public function cklph_wdl_joturl_settings( $request ) {
$joturl_public = $request['public'];
$joturl_private = $request['private'];
$wc_product = new Cklph_Wdl_Wc_Products();
$product = $wc_product->get_single_wc_product_id();
update_option( 'joturl_private', $joturl_private );
update_option( 'joturl_public', $joturl_public );
$rest_url = $this->cklph_wdl_check_rest( $product, 'joturl' );
if ( ! is_numeric( $rest_url ) ) {
update_option( 'joturl_public', '' );
update_option( 'joturl_private', '' );
update_option( 'url_options', 'none' );
return new WP_REST_Response( $rest_url );
}
$response = new WP_REST_Response( 200 );
return $response;
}
/**
* Activate/deactivate shortener provider
*
* @param string $request shortener provider.
* @return string $result url_options.
*/
public function cklph_wdl_activate( $request ) {
$option = $request['shortlink'];
$url_option = get_option( 'url_options' );
$wc_product = new Cklph_Wdl_Wc_Products();
$product = $wc_product->get_single_wc_product_id();
$rest_url = $this->cklph_wdl_check_rest( $product, $option );
if ( ! is_numeric( $rest_url ) ) {
return new WP_REST_Response( $rest_url );
}
if ( $url_option !== $option ) {
update_option( 'url_options', $option );
} else {
update_option( 'url_options', 'none' );
}
$new_option = get_option( 'url_options' );
$response = new WP_REST_Response( $new_option );
return $response;
}
/**
* Force refresh joturl shortlink when refresh link is click twice.
*
* @param int $request item id of product.
* @return $response refreshed link || error.
*/
public function cklph_wdl_force_joturl( $request ) {
$item_id = $request['id'];
$url_option = get_option( 'url_options' );
$home_url = home_url( 'checkout/?add-to-cart=' . intval( $item_id ) . '&quantity=1' );
if ( 'joturl' === $url_option ) {
$rest_url = $this->cklph_wdl_check_rest( $item_id, 'force-joturl' );
$failed = new WP_REST_Response( array( $home_url, $rest_url ) );
$get_url = get_post_meta( $item_id, 'joturl_link', true );
$success = new WP_REST_Response( array( $get_url, $rest_url ) );
$result = is_numeric( $rest_url ) ? $success : $failed;
return $result;
}
return $this->cklph_wdl_refresh( $item_id );
}
/**
* Refresh shortlink when refresh link is click.
*
* @param int $request item id of product.
* @return $response refreshed link.
*/
public function cklph_wdl_refresh( $request ) {
$item_id = empty( $request['id'] ) ? $request : $request['id'];
$url_option = get_option( 'url_options' );
$home_url = home_url( 'checkout/?add-to-cart=' . intval( $item_id ) . '&quantity=1' );
$rest_url = $this->cklph_wdl_check_rest( $item_id, $url_option );
$failed = new WP_REST_Response( array( $home_url, $rest_url ) );
switch ( $url_option ) {
case 'tinyurl':
$get_url = get_post_meta( $item_id, 'tinyurl_link', true );
$success = new WP_REST_Response( array( $get_url, $rest_url ) );
$result = is_numeric( $rest_url ) ? $success : $failed;
return $result;
case 'bitly':
$get_url = get_post_meta( $item_id, 'bitly_link', true );
$success = new WP_REST_Response( array( $get_url, $rest_url ) );
$result = is_numeric( $rest_url ) ? $success : $failed;
return $result;
case 'yourls':
$get_url = get_post_meta( $item_id, 'yourls_link', true );
$success = new WP_REST_Response( array( $get_url, $rest_url ) );
$result = is_numeric( $rest_url ) ? $success : $failed;
return $result;
case 'joturl':
$get_url = get_post_meta( $item_id, 'joturl_link', true );
$success = new WP_REST_Response( array( $get_url, $rest_url ) );
$result = is_numeric( $rest_url ) ? $success : $failed;
return $result;
case 'none':
$success_response = new WP_REST_Response( array( $home_url, 200 ) );
return $success_response;
default:
$success_response = new WP_REST_Response( array( $home_url, 200 ) );
return $success_response;
}
}
/**
* Refresh all shortlink when refresh link is click in settings page.
*
* @param int $request all ids of products.
* @return $response refreshed link || error.
*/
public function cklph_wdl_bulk_refresh( $request ) {
$wc_products = new Cklph_Wdl_Wc_Products();
$products = $wc_products->get_all_wc_product_ids();
$url_option = get_option( 'url_options' );
foreach ( $products as $product ) {
$rest_url = $this->cklph_wdl_check_rest( $product, $url_option );
if ( ! is_numeric( $rest_url ) ) {
return new WP_REST_Response( $rest_url );
}
}
$success_response = new WP_REST_Response( 200 );
return $success_response;
}
/**
* Run shortlink rest api and check for errors.
*
* @param int $item_id product id.
* @param string $url_option url option for shortener.
* @return $shortlink error.
*/
protected function cklph_wdl_check_rest( $item_id, $url_option ) {
$shortlink = new Cklph_Wdl_Shortlinks();
switch ( $url_option ) {
case 'tinyurl':
return $shortlink->cklph_wdl_check_tinyurl( $item_id );
case 'bitly':
return $shortlink->cklph_wdl_check_bitly( $item_id );
case 'yourls':
return $shortlink->cklph_wdl_check_yourls( $item_id );
case 'joturl':
return $shortlink->cklph_wdl_check_joturl( $item_id );
case 'force-joturl':
return $shortlink->cklph_wdl_check_force_joturl( $item_id );
default:
return 'none';
}
}
}
}

View File

@ -0,0 +1,616 @@
<?php
/**
* A class that generates the shortlinks
*
* Defines the api calls of the url-shortener used in the plugin
*
* @link https://chykalophia.com/woocommerce-direct-links
* @since 0.1.0
*
* @package Woocommerce_Direct_Links
* @subpackage Woocommerce_Direct_Links/admin/partials
*/
if ( ! defined( 'ABSPATH' ) ) {
exit();
}
/**
* Check if Cklph_Wdl_shortlinks exists.
*/
if ( ! class_exists( 'Cklph_Wdl_Shortlinks' ) ) {
/**
* Class for shortlink API
*/
class Cklph_Wdl_Shortlinks {
/**
* Converts a url into tinyurl link.
*
* @param int $item_id item_id of product.
* @return $response if error occur.
*/
protected function cklph_wdl_get_tinyurl( $item_id ) {
$tinyurl_site = get_option( 'tinyurl_domain' );
$domain = empty( $tinyurl_site ) ? 'tiny.one' : $tinyurl_site;
$access_token = get_option( 'tinyurl_access_token_options' );
$get_url = get_post_meta( $item_id, 'tinyurl_link', true );
$home_url = home_url( 'checkout/?add-to-cart=' . intval( $item_id ) . '&quantity=1' );
// If user has API key run this function.
if ( ! empty( $access_token ) ) {
$headers = array(
'Authorization' => 'Bearer ' . $access_token,
'Content-Type' => 'application/json',
);
$tinyurl_payload = array(
'url' => $home_url,
'domain' => $domain,
);
$tinyurl_payload_encode = wp_json_encode( $tinyurl_payload );
$tinyurl_request = wp_remote_post(
'https://api.tinyurl.com/create',
array(
'method' => 'POST',
'headers' => $headers,
'body' => $tinyurl_payload_encode,
)
);
$response_code = wp_remote_retrieve_response_code( $tinyurl_request );
$tinyurl_body = wp_remote_retrieve_body( $tinyurl_request );
$tinyurl_decode = json_decode( $tinyurl_body );
if ( 200 === (int) $response_code ) {
$tinyurl = $tinyurl_decode->data->tiny_url;
if ( empty( $get_url ) || $tinyurl !== $get_url ) {
update_post_meta( $item_id, 'tinyurl_link', $tinyurl );
$response = array(
'response_code' => $response_code,
'message' => 'OK',
);
return $response;
}
$response = array(
'response_code' => $response_code,
'message' => 'Exists',
);
return $response;
} elseif ( 400 === (int) $response_code ) {
$response = array(
'response_code' => $response_code,
'message' => 'Bad Request',
);
return $response;
} elseif ( 403 === (int) $response_code ) {
$response = array(
'response_code' => $response_code,
'message' => 'FORBIDDEN',
);
return $response;
} elseif ( 401 === (int) $response_code ) {
update_option( 'tinyurl_access_token_options', '' );
$response = array(
'response_code' => $response_code,
'message' => $tinyurl_decode->errors[0],
);
return $response;
} else {
$response = array(
'response_code' => $response_code,
'message' => $tinyurl_decode->errors[0],
);
return $response;
}
} else {
$tinyurl_request = wp_remote_post( 'https://tinyurl.com/api-create.php?url=' . $home_url );
$response_code = wp_remote_retrieve_response_code( $tinyurl_request );
$tinyurl = wp_remote_retrieve_body( $tinyurl_request );
if ( 200 === (int) $response_code ) {
if ( empty( $get_url ) || $tinyurl !== $get_url ) {
update_post_meta( $item_id, 'tinyurl_link', $tinyurl );
$response = array(
'response_code' => $response_code,
'message' => 'OK',
);
return $response;
}
$response = array(
'response_code' => $response_code,
'message' => 'Exists',
);
return $response;
} else {
$response = array(
'response_code' => $response_code,
'message' => $tinyurl,
);
return $response;
}
}
}
/**
* Validates tinyurl.
*
* @param int $item item_id of product.
* @return string
*/
public function cklph_wdl_check_tinyurl( $item ) {
$tinyurl_domain = get_option( 'tinyurl_domain' );
$access_token = get_option( 'tinyurl_access_token_options' );
if ( ! empty( $tinyurl_domain ) && empty( $access_token ) ) {
return '401-tinyurl';
}
$tinyurl_response = $this->cklph_wdl_get_tinyurl( $item );
$tinyurl_response_code = $tinyurl_response['response_code'];
$tinyurl_response_body = $tinyurl_response['message'];
if ( 422 === (int) $tinyurl_response_code ) {
return '422-tinyurl';
}
switch ( $tinyurl_response_body ) {
case 'OK':
return 201;
case 'Exists':
return 200;
default:
$i18n_code = empty( $tinyurl_response_code ) ? '0' : $tinyurl_response_code;
$i18n_body = empty( $tinyurl_response_body ) ? 'Unknown Error.' : $tinyurl_response_body;
/*
* Translators: %1$d: tinyurl response code.
* Translators: %2$s: tinyurl error message.
*/
return sprintf( __( 'An Error has occured. Error code: %1$d : %2$s', 'woocommerce-direct-links' ), intval( $i18n_code ), esc_attr( $i18n_body ) );
}
}
/**
* Returns the headers based from the parameters
*
* @param string $host The host API.
* @param string $access_token The authorization token from the API.
* @param string $content_type Specifiy the media tpye of the resource.
* @return array
*/
protected function cklph_wdl_get_api_headers( $host, $access_token, $content_type ) {
return array(
'Host' => $host,
'Authorization' => 'Bearer ' . $access_token,
'Content-Type' => $content_type,
);
}
/**
* Http request GET the group_guid for bitly url.
*
* @return @group_guid | @guid_response
*/
protected function cklph_wdl_group_guid() {
$access_token = get_option( 'bitly_access_token_options' );
$headers = $this->cklph_wdl_get_api_headers( 'api-ssl.bitly.com', $access_token, 'application/json' );
$guid_request = wp_remote_get(
'https://api-ssl.bitly.com/v4/groups',
array(
'timeout' => 0,
'headers' => $headers,
)
);
$guid_response_code = wp_remote_retrieve_response_code( $guid_request );
$guid_body = wp_remote_retrieve_body( $guid_request );
$guid_json = json_decode( $guid_body );
if ( 200 !== (int) $guid_response_code ) {
$guid_response = array(
'response_code' => $guid_response_code,
'message' => $guid_json->message,
);
return $guid_response;
}
$guid_response = array(
'response_code' => $guid_response_code,
'message' => $guid_json->groups[0]->guid,
);
return $guid_response;
}
/**
* Converts a url into a bitly link
*
* @param int $item_id item_id_id of product.
* @return @response return the error response and message if error occured.
*/
protected function cklph_wdl_get_bitly( $item_id ) {
$access_token = get_option( 'bitly_access_token_options' );
$headers = $this->cklph_wdl_get_api_headers( 'api-ssl.bitly.com', $access_token, 'application/json' );
$long_url = home_url( 'checkout/?add-to-cart=' . intval( $item_id ) . '&quantity=1' );
$bitly_payload = array(
'long_url' => $long_url,
'group_guid' => $this->cklph_wdl_group_guid()['message'],
);
$bitly_payload_encode = wp_json_encode( $bitly_payload );
$bitly_request = wp_remote_post(
'https://api-ssl.bitly.com/v4/shorten',
array(
'method' => 'POST',
'headers' => $headers,
'body' => $bitly_payload_encode,
)
);
$response_code = wp_remote_retrieve_response_code( $bitly_request );
$bitly_body = wp_remote_retrieve_body( $bitly_request );
$bitly_decode = json_decode( $bitly_body );
if ( 201 < (int) $response_code ) {
$response = array(
'response_code' => $response_code,
'message' => $bitly_decode->message,
);
return $response;
}
if ( 200 === (int) $response_code || 201 === (int) $response_code ) {
$get_url = get_post_meta( $item_id, 'bitly_link', true );
if ( empty( $get_url ) || $get_url !== $bitly_decode->link ) {
update_post_meta( $item_id, 'bitly_link', $bitly_decode->link );
$response = array(
'response_code' => $response_code,
'message' => 'OK',
);
return $response;
}
$response = array(
'response_code' => $response_code,
'message' => 'Exists',
);
return $response;
}
}
/**
* Validates the bitly API Key.
*
* @param int $item item_id of product.
* @return string
*/
public function cklph_wdl_check_bitly( $item ) {
$access_token = get_option( 'bitly_access_token_options' );
if ( empty( $access_token ) ) {
return '401-bitly';
}
$group_guid_response = $this->cklph_wdl_group_guid();
$guid_response_code = $group_guid_response['response_code'];
$guid_response_body = $group_guid_response['message'];
if ( 200 !== (int) $guid_response_code ) {
$i18n_code = empty( $guid_response_code ) ? '0' : $guid_response_code;
$i18n_body = empty( $guid_response_body ) ? 'Unknown error.' : $guid_response_body;
/*
* Translators: %1$d: bitly response code.
* Translators: %2$s: bitly error message.
*/
return sprintf( __( 'An Error has occured while validating API key for Bitly. Error code: %1$d : %2$s', 'woocommerce-direct-links' ), intval( $i18n_code ), esc_attr( $i18n_body ) );
}
$bitly_response = $this->cklph_wdl_get_bitly( $item );
$bitly_response_code = $bitly_response['response_code'];
$bitly_response_body = $bitly_response['message'];
switch ( $bitly_response_body ) {
case 'OK':
return 201;
case 'Exists':
return 200;
default:
$i18n_code = empty( $bitly_response_code ) ? '0' : $bitly_response_code;
$i18n_body = empty( $bitly_response_body ) ? 'Unknown Error.' : $bitly_response_body;
/*
* Translators: %1$d: bitly response code.
* Translators: %2$s: bitly error message.
*/
return sprintf( __( 'An Error has occured while validating API key for Bitly. Error code: %1$d : %2$s', 'woocommerce-direct-links' ), intval( $i18n_code ), esc_attr( $i18n_body ) );
}
}
/**
* Converts a url into joturl.
*
* @param int $item_id item_id of product.
* @return $response if error occur.
*/
protected function cklph_wdl_get_joturl( $item_id ) {
$get_url = get_post_meta( $item_id, 'joturl_link', true );
if ( empty( $get_url ) ) {
$joturl_private = get_option( 'joturl_private' );
$joturl_public = get_option( 'joturl_public' );
$home_url = home_url( 'checkout/?add-to-cart=' . intval( $item_id ) . '&quantity=1' );
$joturl_request = wp_remote_post( 'https://api.joturl.com/a/v1/shorten?login=' . $joturl_public . '&key=' . $joturl_private . '&url=' . $home_url . '' );
$response_code = wp_remote_retrieve_response_code( $joturl_request );
$joturl_body = wp_remote_retrieve_body( $joturl_request );
$joturl_decode = json_decode( $joturl_body );
if ( 200 === (int) $response_code ) {
$joturl = $joturl_decode->result->short_url;
update_post_meta( $item_id, 'joturl_link', $joturl );
$response = array(
'response_code' => $response_code,
'message' => 'OK',
);
return $response;
} else {
$response = array(
'response_code' => $response_code,
'message' => $joturl_decode->status->text,
);
return $response;
}
}
$response = array(
'response_code' => 409,
'message' => 'Exists',
);
return $response;
}
/**
* Validates the JotURL API Keys.
*
* @param int $item_id item_id of product.
* @return string
*/
public function cklph_wdl_check_joturl( $item_id ) {
$joturl_private_key = get_option( 'joturl_private' );
$joturl_public_key = get_option( 'joturl_public' );
if ( empty( $joturl_private_key ) || empty( $joturl_public_key ) ) {
return '401-joturl';
}
$joturl_response = $this->cklph_wdl_get_joturl( $item_id );
$joturl_response_code = $joturl_response['response_code'];
$joturl_response_body = $joturl_response['message'];
switch ( $joturl_response_body ) {
case 'OK':
return 201;
case 'Exists':
return 200;
default:
$i18n_code = empty( $joturl_response_code ) ? '0' : $joturl_response_code;
$i18n_body = empty( $joturl_response_body ) ? 'Unknown Error.' : $joturl_response_body;
/*
* Translators: %1$d: joturl response code.
* Translators: %2$s: joturl error message.
*/
return sprintf( __( 'An Error has occured while validating API keys for JotURL. Error code: %1$d : %2$s', 'woocommerce-direct-links' ), intval( $i18n_code ), esc_attr( $i18n_body ) );
}
}
/**
* Force convert a url into joturl.
*
* @param int $item_id item_id of product.
* @return $response if error occur.
*/
protected function cklph_wdl_force_get_joturl( $item_id ) {
$joturl_private = get_option( 'joturl_private' );
$joturl_public = get_option( 'joturl_public' );
$home_url = home_url( 'checkout/?add-to-cart=' . intval( $item_id ) . '&quantity=1' );
$joturl_request = wp_remote_post( 'https://api.joturl.com/a/v1/shorten?login=' . $joturl_public . '&key=' . $joturl_private . '&url=' . $home_url . '' );
$response_code = wp_remote_retrieve_response_code( $joturl_request );
$joturl_body = wp_remote_retrieve_body( $joturl_request );
$joturl_decode = json_decode( $joturl_body );
if ( 200 === (int) $response_code ) {
$joturl = $joturl_decode->result->short_url;
update_post_meta( $item_id, 'joturl_link', $joturl );
$response = array(
'response_code' => $response_code,
'message' => 'OK',
);
return $response;
} else {
$response = array(
'response_code' => $response_code,
'message' => $joturl_decode->status->text,
);
return $response;
}
}
/**
* Validates the JotURL API Keys when JotURL is forced to refresh link.
*
* @param int $item_id item_id of product.
* @return string
*/
public function cklph_wdl_check_force_joturl( $item_id ) {
$joturl_private_key = get_option( 'joturl_private' );
$joturl_public_key = get_option( 'joturl_public' );
if ( empty( $joturl_private_key ) || empty( $joturl_public_key ) ) {
return '401-joturl';
}
$joturl_response = $this->cklph_wdl_force_get_joturl( $item_id );
$joturl_response_code = $joturl_response['response_code'];
$joturl_response_body = $joturl_response['message'];
switch ( $joturl_response_body ) {
case 'OK':
return 201;
case 'Exists':
return 200;
default:
$i18n_code = empty( $joturl_response_code ) ? '0' : $joturl_response_code;
$i18n_body = empty( $joturl_response_body ) ? 'Unknown Error.' : $joturl_response_body;
/*
* Translators: %1$d: joturl response code.
* Translators: %2$s: joturl error message.
*/
return sprintf( __( 'An Error has occured while validating API keys for JotURL. Error code: %1$d : %2$s', 'woocommerce-direct-links' ), intval( $i18n_code ), esc_attr( $i18n_body ) );
}
}
/**
* Converts checkout links to YoURLS.
*
* @param int $item_id id of product.
* @return @response if error occur.
*/
protected function cklph_wdl_get_yourls( $item_id ) {
$get_url = get_post_meta( $item_id, 'yourls_link', true );
$home_url = home_url( 'checkout/?add-to-cart=' . intval( $item_id ) . '&quantity=1' );
$signature = get_option( 'yourls_signature' );
$domain = get_option( 'yourls_domain' );
$yourls_request = wp_remote_post( 'http://' . $domain . '/yourls-api.php?format=json&action=shorturl&signature=' . $signature . '&url=' . $home_url . '' );
$response_code = wp_remote_retrieve_response_code( $yourls_request );
$yourls_body = wp_remote_retrieve_body( $yourls_request );
$yourls_decode = json_decode( $yourls_body );
switch ( $response_code ) {
case 200:
if ( empty( $get_url ) || $yourls_decode->shorturl !== $get_url ) {
update_post_meta( $item_id, 'yourls_link', $yourls_decode->shorturl );
$response = array(
'response_code' => $response_code,
'message' => 'OK',
);
return $response;
}
$response = array(
'response_code' => $response_code,
'message' => 'Exists',
);
return $response;
case 400:
if ( empty( $get_url ) || $yourls_decode->shorturl !== $get_url ) {
update_post_meta( $item_id, 'yourls_link', $yourls_decode->shorturl );
$response = array(
'response_code' => $response_code,
'message' => 'OK',
);
return $response;
}
$response = array(
'response_code' => $response_code,
'message' => 'Exists',
);
return $response;
case 0:
$response = array(
'response_code' => 404,
'message' => 'Site not found',
);
return $response;
case 403:
$response = array(
'response_code' => 403,
'message' => 'Please use a valid YoURLS Signature',
);
return $response;
default:
$response = array(
'response_code' => $response_code,
'message' => $yourls_decode->message,
);
return $response;
}
}
/**
* Validates the YoURLS Signature.
*
* @param int $item item_id of product.
* @return string
*/
public function cklph_wdl_check_yourls( $item ) {
$yourls_signature = get_option( 'yourls_signature' );
$yourls_domain = get_option( 'yourls_domain' );
if ( empty( $yourls_signature ) || empty( $yourls_domain ) ) {
return '401-yourls';
}
$yourls_response = $this->cklph_wdl_get_yourls( $item );
$yourls_response_code = $yourls_response['response_code'];
$yourls_response_body = $yourls_response['message'];
switch ( $yourls_response_body ) {
case 'OK':
return 201;
case 'Exists':
return 200;
default:
$i18n_code = empty( $yourls_response_code ) ? '0' : $yourls_response_code;
$i18n_body = empty( $yourls_response_body ) ? 'Unknown Error.' : $yourls_response_body;
/*
* Translators: %1$d: YoURLS response code.
* Translators: %2$s: YoURLS error message.
*/
return sprintf( __( 'An Error has occured while validating YoURLS credentials. Error code: %1$d : %2$s', 'woocommerce-direct-links' ), intval( $i18n_code ), esc_attr( $i18n_body ) );
}
}
/**
* Get shortlink to use in list tables.
*
* @param int $item_id ID of product.
* @return @turl shortlink
*/
public function cklph_wdl_get_link( $item_id ) {
$url_option = get_option( 'url_options' );
$home_url = esc_url( home_url( 'checkout/?add-to-cart=' . intval( $item_id ) . '&quantity=1' ) );
switch ( $url_option ) {
case 'tinyurl':
$get_url = get_post_meta( $item_id, 'tinyurl_link', true );
$url = empty( $get_url ) ? $home_url : $get_url;
break;
case 'bitly':
$get_url = get_post_meta( $item_id, 'bitly_link', true );
$url = empty( $get_url ) ? $home_url : $get_url;
break;
case 'yourls':
$get_url = get_post_meta( $item_id, 'yourls_link', true );
$url = empty( $get_url ) ? $home_url : $get_url;
break;
case 'joturl':
$get_url = get_post_meta( $item_id, 'joturl_link', true );
$url = empty( $get_url ) ? $home_url : $get_url;
break;
case 'none':
default:
$url = $home_url;
}
return $url;
}
}
}

View File

@ -0,0 +1,179 @@
<?php
/**
* A class that gets data from woocommerce products.
*
* Defines the product queries for the plugin
*
* @link https://chykalophia.com/woocommerce-direct-links
* @since 0.1.0
*
* @package Woocommerce_Direct_Links
* @subpackage Woocommerce_Direct_Links/admin/partials
*/
if ( ! defined( 'ABSPATH' ) ) {
return;
}
if ( ! class_exists( 'Cklph_Wdl_Wc_Products' ) ) {
/**
* Handles all queries concerning woocommerce products.
*/
class Cklph_Wdl_Wc_Products {
/**
* Gets all product ids to create shortlinks.
*
* @return @product_lists array of IDs
*/
public function get_all_wc_product_ids() {
$product_lists = array();
$args = $this->get_wc_query_args( 'publish', -1, array( 'simple', 'variable', 'subscription', 'variable-subscription' ), 'ids' );
$product_ids = wc_get_products( $args );
foreach ( $product_ids as $product_id ) {
$prod_var = new WC_Product_Variable( $product_id );
$variations = $prod_var->get_available_variations( 'objects' );
if ( ! empty( $variations ) ) {
foreach ( $variations as $variation ) {
$product_lists[] = $variation->get_id();
}
} else {
$product_lists[] = $product_id;
}
}
return $product_lists;
}
/**
* Gets the necessarry product data to display in list table.
*
* @param array $args Query arguments for wc_get_products.
* @return array
*/
public function get_all_wc_products_data( $args ) {
$product_list = array();
$products = wc_get_products( $args );
foreach ( $products as $product ) {
// Get product details.
$prod_id = $product->get_id();
$prod_link = $product->get_permalink();
$prod_thumbnail = $product->get_image( array( 50, 50 ) );
$prod_title = $product->get_title();
$category = wc_get_product_category_list( $prod_id );
$prod_sku = $product->get_sku();
$prod_var = new WC_Product_Variable( $prod_id );
$variations = $prod_var->get_available_variations( 'objects' );
if ( count( $variations ) > 1 ) {
foreach ( $variations as $vars ) {
// Get specific variation details.
$var_id = $vars->get_id();
$var_sku = $vars->get_sku();
$var_thumbnail = $vars->get_image( array( 50, 50 ) );
$var_attributes = wc_get_formatted_variation( $vars, 'true' );
$product_list[] = array(
'ID' => esc_attr( $prod_id ),
'variation_id' => esc_attr( $var_id ),
'post_title' => esc_attr( $product->get_formatted_name() ),
'sku' => ! empty( $var_sku ) ? esc_attr( $var_sku ) : '<span class="na">&ndash;</span>',
'attrib' => esc_attr( $var_attributes ),
'thumb' => $var_thumbnail,
'category' => $category,
'guid' => esc_attr( $prod_link ),
);
}
} else {
$product_list[] = array(
'ID' => esc_attr( $prod_id ),
'post_title' => esc_attr( $prod_title ),
'sku' => ! empty( esc_attr( $prod_sku ) ) ? esc_attr( $prod_sku ) : '<span class="na">&ndash;</span>',
'attrib' => '<span class="na">&ndash;</span>',
'thumb' => $prod_thumbnail,
'category' => $category,
'guid' => esc_attr( $prod_link ),
);
}
}
return $product_list;
}
/**
* Gets the necessarry product data to display on product meta box.
*
* @return array
*/
public function get_metabox_product_data() {
$product_list = array();
$product = wc_get_product( get_the_ID() );
$product_variable = new WC_Product_Variable( $product );
$variations = $product_variable->get_available_variations( 'objects' );
if ( ! empty( $variations ) ) {
foreach ( $variations as $vars ) {
$product_list[] = array(
'ID' => esc_attr( $vars->get_id() ),
'post_title' => esc_attr( $product->get_formatted_name() ),
'sku' => esc_attr( $vars->get_sku() ),
'attrib' => esc_attr( wc_get_formatted_variation( $vars, 'true' ) ),
'thumb' => $vars->get_image( array( 50, 50 ) ),
'guid' => esc_attr( $product->get_permalink() ),
);
}
} else {
$product_list[] = array(
'ID' => esc_attr( get_the_ID() ),
'post_title' => esc_attr( get_the_title() ),
'sku' => esc_attr( $product->get_sku() ),
'attrib' => '<span class="na">&ndash;</span>',
'thumb' => $product->get_image( array( 100, 100 ) ),
'guid' => esc_attr( $product->get_permalink() ),
);
}
return $product_list;
}
/**
* Returns the ID of the most recent product.
*
* @return string Product ID.
*/
public function get_single_wc_product_id() {
$args = $this->get_wc_query_args( 'publish', 1, array( 'simple', 'variable', 'subscription', 'variable-subscription' ), 'ids' );
$product = wc_get_products( $args );
return $product;
}
/**
* Returns the query args for woocommerce products.
*
* @param string $status The post status.
* @param string $limit The number of products to be returned.
* @param array $type The type of products to be returned.
* @param string $return The return type.
* @return array
*/
public function get_wc_query_args( $status, $limit, $type = array(), $return = 'objects' ) {
return array(
'status' => $status,
'limit' => $limit,
'type' => $type,
'return' => $return,
);
}
}
}

View File

@ -0,0 +1,462 @@
<?php
/**
* The list-table class that defines the product details and its add to cart url
*
* Get the product name, sku, thumbnail, and category of a woocommerce product and its checkout
* link.
*
* @link https://chykalophia.com/woocommerce-direct-links
* @since 0.1.0
* @package Woocommerce_Direct_Links
* @subpackage Woocommerce_Direct_Links/admin/partials/list-table
*/
if ( ! defined( 'ABSPATH' ) ) {
exit();
}
if ( ! class_exists( 'Cklph_WP_List_Table' ) ) {
require_once 'class-wp-list-table.php';
}
if ( ! class_exists( 'Cklph_Wdl_List_Table' ) ) {
/**
* Edited list table class
*/
class Cklph_Wdl_List_Table extends Cklph_WP_List_Table {
/**
* Product_List_Table constructor.
*/
public function __construct() {
// Set parent defaults.
parent::__construct(
array(
'singular' => 'product',
'plural' => 'products',
'ajax' => false,
)
);
}
/**
* Defines the columns to use in your listing table
*
* @return array
*/
public function manage_columns() {
// Columns for admin list table.
$columns = array(
'thumb' => '<span class="wc-image tips" data-tip="' . esc_attr__( 'Image', 'woocommerce-direct-links' ) . '">' . __( 'Image', 'woocommerce-direct-links' ) . '</span>',
'post_title' => __( 'Product Name', 'woocommerce-direct-links' ),
'sku' => __( 'SKU', 'woocommerce-direct-links' ),
'attrib' => __( 'Attributes', 'woocommerce-direct-links' ),
'category' => __( 'Category', 'woocomerce-direct-links' ),
'guid' => __( 'Add to Cart Link', 'woocommerce-direct-links' ),
'copy' => __( 'Copy Link', 'woocommerce-direct-links' ),
'refresh' => __( 'Refresh Link', 'woocommerce-direct-links' ),
);
// remove category column for metabox list table.
if ( 'product' === $this->screen->id ) {
array_splice( $columns, 4, 1 );
}
return $columns;
}
/**
* Override the parent columns method for screen options columns.
*
* @return Array
*/
public function get_columns() {
// Columns for screen options.
$columns = array(
'thumb' => __( 'Thumbnail', 'woocommerce-direct-links' ),
'sku' => __( 'SKU', 'woocommerce-direct-links' ),
'attrib' => __( 'Attributes', 'woocommerce-direct-links' ),
'category' => __( 'Category', 'woocomerce-direct-links' ),
);
return $columns;
}
/**
* Define which columns are hidden
*
* @return Array
*/
public function get_hidden_columns() {
return array();
}
/**
* Define what data to show on each column of the table
*
* @param Array $item Data.
* @param String $column_name Current column name.
*
* @return Mixed
*/
public function column_default( $item, $column_name ) {
switch ( $column_name ) {
case 'sku':
case 'attrib':
case 'thumb':
case 'category':
return $item[ $column_name ];
default:
return print_r( $item, true );
}
}
/**
* Prepare the items for the table to process
*
* @return void
*/
public function prepare_items() {
$search = '';
$category = '';
$primary = 'post_title';
$columns = $this->manage_columns();
$sortable = $this->get_sortable_columns();
$get_hidden_columns = $this->get_hidden_columns();
$get_hidden_options = get_user_option( 'manage' . $this->screen->id . 'columnshidden' );
$hidden = is_array( $get_hidden_options ) ? $get_hidden_options : $get_hidden_columns;
if ( isset( $_GET['s'] ) ) {
$search = sanitize_text_field( wp_unslash( $_GET['s'] ) );
}
if ( isset( $_GET['product_cat'] ) ) {
$category = sanitize_text_field( wp_unslash( $_GET['product_cat'] ) );
}
$data = $this->get_data( $search, $category );
usort( $data, array( &$this, 'sort_data' ) );
$per_page = get_user_meta( get_current_user_id(), 'cklph_wdl_per_page', true );
if ( empty( $per_page ) ) {
$per_page = $this->screen->get_option( 'per_page', 'default' );
}
$current_page = $this->get_pagenum();
$total_items = count( $data );
$this->set_pagination_args(
array(
'total_items' => $total_items,
'per_page' => $per_page,
)
);
$data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ), $per_page );
$this->_column_headers = array( $columns, $hidden, $sortable, $primary );
if ( 'product' === $this->screen->id ) {
$this->_column_headers = array( $columns, $hidden, $sortable, $primary );
}
$this->items = $data;
}
/**
* Retrieves product data. Inlcudes search and filter functions
*
* @param string $search search filter.
* @param string $category category filter.
* @return Array
*/
public function get_data( $search = '', $category = '' ) {
$wc_products = new Cklph_Wdl_Wc_Products();
$productlist = array();
if ( isset( $search ) ) {
$args = array(
'status' => 'publish',
'limit' => -1,
'orderby' => 'title',
'order' => 'ASC',
'type' => array( 'simple', 'variable', 'subscription', 'variable-subscription' ),
's' => $search,
'meta_query' => array(
array(
'key' => '_sku',
'value' => $search,
'compare' => 'LIKE',
),
array(
'key' => '_title',
'value' => $search,
'compare' => 'LIKE',
),
),
);
} else {
$args = array(
'status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
'limit' => -1,
'type' => array( 'simple', 'variable', 'subscription', 'variable-subscription' ),
);
}
if ( isset( $category ) ) {
$args['category'] = $category;
}
if ( 'toplevel_page_cklph-wdl-admin' === $this->screen->id && is_admin() ) {
$productlist = $wc_products->get_all_wc_products_data( $args );
} else {
$productlist = $wc_products->get_metabox_product_data();
}
return $productlist;
}
/**
* Custom row display for Post title
*
* @param int $item item data.
* @return String
*/
protected function column_post_title( $item ) {
$item_id = $item['ID'];
$item_guid = $item['guid'];
$item_title = $item['post_title'];
// Only shows the id / variation id as actions in meta box.
if ( 'product' === $this->screen->id ) {
$actions = array(
'ID' => sprintf(
'<b>%s: %s</b>',
__( 'ID', 'woocommerce-direct-links' ),
esc_attr( $item_id )
),
);
if ( isset( $item['variation_id'] ) ) {
array_splice(
$actions,
1,
0,
array(
'variation_id' => sprintf(
'%s: %s',
__( 'Variation ID', 'woocommerce-direct-links' ),
esc_attr( $item['variation_id'] )
),
)
);
}
} else {
$actions = array(
'ID' => sprintf(
'<b>%s: %s</b>',
__( 'ID', 'woocommerce-direct-links' ),
esc_attr( $item_id )
),
'edit' => sprintf(
'<a href="%s">%s</a>',
esc_attr( get_edit_post_link( $item_id ) ),
__( 'Edit', 'woocommerce-direct-links' )
),
'view' => sprintf(
'<a href="%s">%s</a>',
esc_attr( $item_guid ),
__( 'View', 'woocommerce-direct-links' )
),
);
if ( isset( $item['variation_id'] ) ) {
array_splice(
$actions,
1,
0,
array(
'variation_id' => sprintf(
'%s: %s',
__( 'Variation ID', 'woocommerce-direct-links' ),
esc_attr( $item['variation_id'] )
),
)
);
}
}
return sprintf(
'<a href="%1$s"><strong>%2$s</strong></a>%3$s',
esc_attr( $item_guid ),
esc_attr( $item_title ),
$this->row_actions( $actions )
);
}
/**
* Custom row display for Copy column. Prints the copy button
*
* @param int $item item data.
* @return String
*/
protected function column_copy( $item ) {
$id = array_key_exists( 'variation_id', $item ) ? $item['variation_id'] : $item['ID'];
return sprintf(
'<div class="tooltip">
<button class="button-primary" type="button" onclick="cklph_wdl_copyurl(%1$d)" onmouseout="cklph_wdl_out(%1$d)">
<span class="tooltiptext" id="myTooltip-%1$d">Copy</span>
%2$s
</button>
</div>',
esc_attr( $id ),
__( 'Copy Link', 'woocommerce-direct-links' ),
);
}
/**
* Custom row display for Refresh Link Button.
*
* @param array $item Item data.
* @return String
*/
protected function column_refresh( $item ) {
$id = array_key_exists( 'variation_id', $item ) ? $item['variation_id'] : $item['ID'];
return sprintf(
'<button class="button-primary cklph-wdl-refresh" id="cklph-wdl-btn-%1$d" type="button" onclick=cklph_wdl_rest(%1$d)>
<span class="cklph-wdl-btn-text">%2$s</span>
</button>',
esc_attr( $id ),
__( 'Refresh Link', 'woocommerce-direct-links' ),
);
}
/**
* Custom row display for the add-to-cart link
*
* @param int $item item data.
* @return String
*/
protected function column_guid( $item ) {
$id = array_key_exists( 'variation_id', $item ) ? $item['variation_id'] : $item['ID'];
$shortlink = new Cklph_Wdl_Shortlinks();
$turl = $shortlink->cklph_wdl_get_link( $id );
return sprintf(
'<input id="cklph-wdl-url-%1$s" class="cklph-wdl-input" type="text" size=30 value="%2$s" readonly>',
esc_attr( $id ),
esc_url( $turl )
);
}
/**
* Adds custom filters at the top.
*
* @param string $which identify if content is top or bottom.
*/
public function extra_tablenav( $which ) {
?>
<div class="alignleft actions">
<?php
if ( 'toplevel_page_cklph-wdl-admin' === $this->screen->id && is_admin() ) {
if ( 'top' === $which ) {
_e( '<form method="GET"><input type="hidden" name="page" value="' . esc_attr( $_REQUEST['page'] ) . '">' );
$args = array();
if ( isset( $_GET['product_cat'] ) ) {
$args['selected'] = sanitize_text_field( $_GET['product_cat'] );
}
wc_product_dropdown_categories( $args );
$output = ob_get_clean();
if ( ! empty( $output ) ) {
echo $output;
submit_button( __( 'Filter', 'woocommerce-direct-links' ), '', 'filter_action', false, array( 'id' => 'site-query-submit' ) );
_e( '</form>' );
}
}
}
?>
</div>
<?php
}
/**
* Define the sortable columns
*
* @return Array
*/
public function get_sortable_columns() {
return array(
'post_title' => array( 'post_title', false ),
'category' => array( 'category', false ),
);
}
/**
* Allows you to sort the data by the variables set in the $_GET
*
* @return Mixed
*/
private function sort_data( $a, $b ) {
if ( 'toplevel_page_cklph-wdl-admin' === $this->screen->id && is_admin() ) {
// Set defaults.
$orderby = 'post_title';
$order = 'asc';
// If orderby is set, use this as the sort column.
if ( ! empty( $_GET['orderby'] ) ) {
$orderby = $_GET['orderby'];
}
// If order is set use this as the order.
if ( ! empty( $_GET['order'] ) ) {
$order = $_GET['order'];
}
$result = strcmp( $a[ $orderby ], $b[ $orderby ] );
if ( 'asc' === $order ) {
return $result;
}
return -$result;
}
}
/**
* Prints the search box of the List Table
*
* @param string $text search query.
* @param int $input_id input id.
*/
public function search_box( $text, $input_id ) {
if ( 'toplevel_page_cklph-wdl-admin' === $this->screen->id && is_admin() ) {
_e( '<form method="GET"><input type="hidden" name="page" value="'.esc_attr( $_REQUEST['page'] ).'">' );
parent::search_box( $text, $input_id );
_e( '</form>' );
}
}
}
}

File diff suppressed because it is too large Load Diff

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.

1
index.php Normal file
View File

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

View File

@ -0,0 +1,107 @@
# Copyright (C) 2022 Joel Sanguenza, Lord Francis Navarro
# This file is distributed under the GPL-2.0+.
msgid ""
msgstr ""
"Project-Id-Version: WooCommerce Direct Links 0.1.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/woocommerce-direct-links\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2022-05-16T17:09:25+02:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.6.0\n"
"X-Domain: woocommerce-direct-links\n"
#. Plugin Name of the plugin
msgid "WooCommerce Direct Links"
msgstr ""
#. Plugin URI of the plugin
msgid "https://chykalophia.com/woocommerce-direct-links"
msgstr ""
#. Description of the plugin
msgid "An extension plugin for Woocommerce which displays the list of products (simple and variable products) and its variations along with its add-to-cart links. These links automatically adds the product or product variation to the cart and redirects the user to the checkout page. You may choose from two (2) url shorteners (Tinyurl and Bitly) to shrink the links."
msgstr ""
#. Author of the plugin
msgid "Joel Sanguenza, Lord Francis Navarro"
msgstr ""
#. Author URI of the plugin
msgid "https://chykalophia.com"
msgstr ""
#: admin/class-cklph-wdl-admin.php:82
#: admin/class-cklph-wdl-admin.php:83
msgid "Woocommerce Direct Links"
msgstr ""
#: admin/class-cklph-wdl-admin.php:93
msgid "WooCommerce Direct Link Settings"
msgstr ""
#: admin/class-cklph-wdl-admin.php:94
msgid "Settings"
msgstr ""
#: admin/class-cklph-wdl-admin.php:130
msgid "Woo Products Checkout URLs"
msgstr ""
#: admin/partials/cklph-wdl-admin-page.php:26
msgid "Search Products"
msgstr ""
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:52
msgid "Product Name"
msgstr ""
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:53
msgid "SKU"
msgstr ""
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:54
msgid "Attributes"
msgstr ""
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:55
msgid "Thumbnail"
msgstr ""
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:57
msgid "Add to Cart Link"
msgstr ""
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:58
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:354
msgid "Copy Link"
msgstr ""
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:278
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:302
msgid "ID"
msgstr ""
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:291
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:325
msgid "Variation ID"
msgstr ""
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:308
msgid "Edit"
msgstr ""
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:313
msgid "View"
msgstr ""
#: admin/partials/list-tables/class-cklph-wdl-list-table.php:419
msgid "Filter"
msgstr ""
#: woocommerce-direct-links.php:68
msgid "Cannot activate WooCommerce Direct Links without WooCommerce installed and activated."
msgstr ""

55
uninstall.php Normal file
View File

@ -0,0 +1,55 @@
<?php
/**
* Fired when the plugin is uninstalled.
*
* When populating this file, consider the following flow
* of control:
*
* - This method should be static
* - Check if the $_REQUEST content actually is the plugin name
* - Run an admin referrer check to make sure it goes through authentication
* - Verify the output of $_GET makes sense
* - Repeat with other user roles. Best directly by using the links/query string parameters.
* - Repeat things for multisite. Once for a single site in the network, once sitewide.
*
* This file may be updated more in future version of the Boilerplate; however, this is the
* general skeleton and outline for how the file should work.
*
* For more information, see the following discussion:
* https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
*
* @link http://example.com
* @since 0.1.0
*
* @package Woocommerce_Direct_Links
*/
// If uninstall not called from WordPress, then exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
$post_args = array(
'post_type' => array( 'product_variation', 'product' ),
'post_status' => 'publish',
'posts_per_page' => -1,
'fields' => 'ids',
);
$query = new WP_Query( $post_args );
foreach ( $query->posts as $product ) {
delete_post_meta( $product, 'bitly_link' );
delete_post_meta( $product, 'joturl_link' );
delete_post_meta( $product, 'yourls_link' );
delete_post_meta( $product, 'tinyurl_link' );
}
delete_option( 'url_options' );
delete_option( 'yourls_domain' );
delete_option( 'joturl_public' );
delete_option( 'tinyurl_domain' );
delete_option( 'joturl_private' );
delete_option( 'yourls_signature' );
delete_option( 'bitly_access_token_options' );
delete_option( 'tinyurl_access_token_options' );

View File

@ -0,0 +1,69 @@
<?php
/**
* Woocomerce Direct Links
*
* @category Wordpress_Plugin
* @package Woocommerce_Direct_Links
* @author Joel Sanguenza <joel@chykalophia.com>
* Lord Francis Navarro <francis@chykalophia.com>
* @license GPL-2.0+ http://www.gnu.org/licenses/gpl-2.0.txt
* @link https://chykalophia.com/woocommerce-direct-links
* @since 0.1.0
*
* @wordpress-plugin
* Plugin Name: WooCommerce Direct Links
* Plugin URI: https://chykalophia.com/woocommerce-direct-links
* Description: An extension plugin for Woocommerce which displays the list of products (simple and variable products) and its variations along with its add-to-cart links. These links automatically adds the product or product variation to the cart and redirects the user to the checkout page. You may choose from two (2) url shorteners (Tinyurl and Bitly) to shrink the links.
* Version: 0.1.0
* Author: Joel Sanguenza, Lord Francis Navarro
* Author URI: https://chykalophia.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: woocommerce-direct-links
* Domain Path: /languages
*/
// If this file is called directly, abort.
if (!defined('ABSPATH')) {
die;
}
/**
* Current plugin version.
*/
define('WDL_VERSION', '0.1.0');
// Constants.
define('CKLPH_WDL_URL', plugin_dir_url(__FILE__));
define('CKLPH_WDL_PATH', plugin_dir_path(__FILE__));
define('CKLPH_WDL_BASE', plugin_basename(__FILE__));
/**
* The code that runs during plugin activation.
*/
function cklph_wdl_activate()
{
flush_rewrite_rules();
}
register_activation_hook(__FILE__, 'cklph_wdl_activate');
register_deactivation_hook(__FILE__, 'cklph_wdl_activate');
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require CKLPH_WDL_PATH . 'includes/class-cklph-wdl.php';
/**
* Begins execution of the plugin.
*
* @since 0.1.0
*/
function run_wdl()
{
$plugin = new Cklph_Wdl(); // To be updated into a singleton class.
$plugin->run();
}
run_wdl();