Skip to content
This repository was archived by the owner on Dec 4, 2019. It is now read-only.

Commit 70a3354

Browse files
committed
Multiple category support + categories in the search
1 parent 1d75918 commit 70a3354

File tree

5 files changed

+112
-25
lines changed

5 files changed

+112
-25
lines changed

functions.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,49 @@ function wpp_admin_notice( $text, $type = 'success' ) {
1515
} );
1616
}
1717

18+
19+
function wpp_remove_domain_from_url( $url ) {
20+
if ( preg_match( '#(?:https?:\/\/)?[^\/]*?(\/.*)#', $url, $matches ) ) {
21+
return $matches[1];
22+
}
23+
24+
return $url;
25+
}
26+
27+
function wpp_get_domain_from_url( $url, $scheme = false ) {
28+
if ( preg_match( '#(https?:\/\/)?([^\/]*?)\/.*#', $url, $matches ) ) {
29+
return $scheme ? $matches[1] . $matches[2] : $matches[2];
30+
}
31+
32+
return $url;
33+
}
34+
1835
/**
19-
* @param WP_Post $post
36+
* @param string $string
2037
* @param string|array $shortcode
2138
*
2239
* @return bool
2340
*/
24-
function wpp_has_shortcode( $post, $shortcode ) {
41+
function wpp_has_shortcode( $string, $shortcode ) {
42+
global $shortcode_tags;
43+
$old = $shortcode_tags;
2544
if ( is_array( $shortcode ) ) {
45+
$shortcode_tags = array_flip( $shortcode );
2646
foreach ( $shortcode as $sh ) {
27-
if ( has_shortcode( $post->post_content, $sh ) ) {
47+
if ( has_shortcode( $string, $sh ) ) {
48+
$shortcode_tags = $old;
2849
return true;
2950
}
3051
}
3152
} else {
32-
if ( has_shortcode( $post->post_content, $shortcode ) ) {
53+
$shortcode_tags = array( $shortcode => '' );
54+
if ( has_shortcode( $string, $shortcode ) ) {
55+
$shortcode_tags = $old;
3356
return true;
3457
}
3558
}
3659

60+
$shortcode_tags = $old;
3761
return false;
3862
}
3963

js/select2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4575,7 +4575,7 @@
45754575
return CloseOnSelect;
45764576
});
45774577

4578-
S2.define('select2/i18n/en', [], function () {
4578+
S2.define('select2/select2-i18n/en', [], function () {
45794579
// English
45804580
return {
45814581
errorLoading: function () {

js/select2.min.js

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Modules/LicenceManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct( WP_Plugin &$parent = null ) {
2929
self::__parentConstruct( $parent );
3030
$this->version = $parent->getVersion();
3131
$this->product_id = $parent->getProductID();
32-
$this->api_url = $parent->getDownloadUrl();
32+
$this->api_url = trailingslashit( wpp_get_domain_from_url( $parent->getBuyUrl(), true ) );
3333
$this->buy_url = $parent->getBuyUrl();
3434
$this->instance = str_replace( array( '/', 'https', 'http', ':' ), array( '' ), network_site_url() );
3535

@@ -263,7 +263,7 @@ public function actionsAndFilters() {
263263
}
264264

265265
public function addSection( ReduxFramework $framework ) {
266-
if ( empty( $this->buy_url ) ) {
266+
if ( empty( $this->buy_url ) || $this->buy_url == trailingslashit( '' ) ) {
267267
return;
268268
}
269269
$url = parse_url( $this->buy_url );

src/Objects/WP_Plugin.php

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ protected function extractFromComment( $comment ) {
265265
$this->download_url = trim( $matches[1] );
266266
}
267267

268-
if ( empty( $this->buy_url ) && $comment && preg_match( '#donate[-\s]?url[:\s]*([^\r\n]*)#i', $comment, $matches ) ) {
268+
if ( empty( $this->buy_url ) && $comment && preg_match( '#donate[-\s]?link[:\s]*([^\r\n]*)#i', $comment, $matches ) ) {
269269
$this->buy_url = trim( $matches[1] );
270270
} elseif ( empty( $this->buy_url ) ) {
271271
$this->buy_url = $this->download_url;
@@ -546,6 +546,33 @@ public function file( $file = '' ) {
546546
return trailingslashit( dirname( $this->file ) ) . ltrim( "$file", '/' );
547547
}
548548

549+
/**
550+
* @param string $name Handle name
551+
* @param string $js Filename (optional extension)
552+
* @param array $require
553+
* @param bool $localize
554+
* @param bool $in_footer
555+
* @param string $async_defer
556+
*
557+
* @return bool|string Handle name if registered false otherwise
558+
*/
559+
public function addExternalScript( $name, $js, $require = array(), $localize = false, $in_footer = false, $async_defer = 'async' ) {
560+
if ( ! did_action( 'init' ) ) {
561+
add_action( 'init', function () use ( $name, $js, $require, $localize, $in_footer ) {
562+
$this->addExternalScript( $name, $js, $require, $localize, $in_footer );
563+
} );
564+
565+
return false;
566+
}
567+
$name = $this->registerExternalScript( $name, $js, $require, $localize, $in_footer, $async_defer );
568+
569+
if ( $name ) {
570+
wp_enqueue_script( $name );
571+
}
572+
573+
return $name;
574+
}
575+
549576
/**
550577
* @param string $js Filename (optional extension)
551578
* @param array $require
@@ -563,6 +590,13 @@ public function addScript( $js, $require = array(), $localize = false, $in_foote
563590

564591
return false;
565592
}
593+
if ( did_action( 'wp_head' ) ) {
594+
$in_footer = true;
595+
}
596+
597+
if ( $in_footer ) {
598+
$async_defer = '';
599+
}
566600
$name = $this->registerScript( $js, $require, $localize, $in_footer, $async_defer );
567601

568602
if ( $name ) {
@@ -573,31 +607,33 @@ public function addScript( $js, $require = array(), $localize = false, $in_foote
573607
}
574608

575609
public function getHandleName( $script ) {
576-
return $this->getSlug() . basename( $script );
610+
return $this->getSlug() . '-' . basename( $script );
577611
}
578612

579613
public function getJsName( $script ) {
580614
return str_replace( array( '-', '.' ), array( '_', '_' ), basename( $script ) );
581615
}
582616

583617
/**
584-
* @param $js
618+
* @param string $name Handle name
619+
* @param string $js Name of the file without extension and js folder
585620
* @param array $require
586-
* @param bool $localize
621+
* @param bool|array $localize
587622
* @param bool $in_footer
588623
* @param string $async_defer
589624
*
590625
* @return bool|string Handle name if registered false otherwise
591626
*/
592-
public function registerScript( $js, $require = array(), $localize = false, $in_footer = false, $async_defer = 'async' ) {
627+
public function registerExternalScript( $name, $js, $require = array(), $localize = false, $in_footer = false, $async_defer = 'async' ) {
593628
if ( ! did_action( 'init' ) ) {
594-
add_action( 'init', function () use ( $js, $require, $localize, $in_footer ) {
595-
$this->registerScript( $js, $require, $localize, $in_footer );
629+
//Poor performances so better to not use this massively
630+
add_action( 'init', function () use ( $name, $js, $require, $localize, $in_footer ) {
631+
$this->registerExternalScript( $name, $js, $require, $localize, $in_footer );
596632
} );
597633

598634
return false;
599635
}
600-
$name = $this->getHandleName( $js );
636+
$name = $this->getHandleName( $name );
601637
if ( ! wp_script_is( $name, 'registered' ) ) {
602638
if ( $file = $this->searchFile( $js, 'js', true, 'js' ) ) {
603639
wp_register_script( $name, $file, $require, $this->version, $in_footer );
@@ -606,6 +642,8 @@ public function registerScript( $js, $require = array(), $localize = false, $in_
606642
if ( wp_script_is( $name, 'registered' ) ) {
607643
if ( ! empty( $async_defer ) ) {
608644
$this->addAsyncDeferAttribute( $name, $async_defer );
645+
} else {
646+
$this->removeAsyncDeferAttribute( $name );
609647
}
610648
if ( ! empty( $localize ) ) {
611649
$this->localizeScript( $js, $localize );
@@ -617,6 +655,19 @@ public function registerScript( $js, $require = array(), $localize = false, $in_
617655
return false;
618656
}
619657

658+
/**
659+
* @param string $js Name of the file without extension and js folder
660+
* @param array $require
661+
* @param bool|array $localize
662+
* @param bool $in_footer
663+
* @param string $async_defer
664+
*
665+
* @return bool|string Handle name if registered false otherwise
666+
*/
667+
public function registerScript( $js, $require = array(), $localize = false, $in_footer = false, $async_defer = 'async' ) {
668+
return $this->registerExternalScript( $js, $js, $require, $localize, $in_footer, $async_defer );
669+
}
670+
620671
public function localizeScript( $js, $localize ) {
621672
global $wpp_localize_scripts;
622673

@@ -638,6 +689,13 @@ public function localizeScript( $js, $localize ) {
638689
wp_localize_script( $this->slug, $this->getJsName( $this->slug ), $wpp_localize_scripts[ $this->slug ] );
639690
}
640691

692+
public function removeAsyncDeferAttribute( $handle ) {
693+
global $wpp_script_handles;
694+
695+
if ( isset( $wpp_script_handles[ $handle ] ) ) {
696+
unset( $wpp_script_handles[ $handle ] );
697+
}
698+
}
641699

642700
public function addAsyncDeferAttribute( $handle, $async_defer = 'async' ) {
643701
global $wpp_script_handles;
@@ -687,14 +745,25 @@ public function addStyle( $css, $media = 'all' ) {
687745
* @return bool|string Handle name if registered false otherwise
688746
*/
689747
public function registerStyle( $css, $media = 'all' ) {
748+
return $this->registerExternalStyle( $css, $css, $media );
749+
}
750+
751+
/**
752+
* @param string $name Handle name
753+
* @param string $css Filename (extension is optional)
754+
* @param string $media
755+
*
756+
* @return bool|string Handle name if registered false otherwise
757+
*/
758+
public function registerExternalStyle( $name, $css, $media = 'all' ) {
690759
if ( ! did_action( 'init' ) ) {
691-
add_action( 'init', function () use ( $css, $media ) {
692-
$this->registerStyle( $css, $media );
760+
add_action( 'init', function () use ( $name, $css, $media ) {
761+
$this->registerExternalStyle( $name, $css, $media );
693762
} );
694763

695764
return false;
696765
}
697-
$name = $this->getHandleName( $css );
766+
$name = $this->getHandleName( $name );
698767
if ( ! wp_style_is( $name, 'registered' ) ) {
699768
if ( $file = $this->searchFile( $css, 'css', true, 'css' ) ) {
700769
wp_register_style( $name, $file, array(), $this->version, $media );

0 commit comments

Comments
 (0)