| 1 |
<?php |
| 2 |
/** |
| 3 |
* Compatibility functions for third party plugins. |
| 4 |
* |
| 5 |
* @since 1.2.2.32 |
| 6 |
* @package userswp |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
class UsersWP_Compatibility { |
| 15 |
|
| 16 |
public function __construct(){ |
| 17 |
if( defined( 'ELEMENTOR_VERSION' ) ){ |
| 18 |
add_action('uwp_bypass_users_list_item_template_content', array($this,'users_list_item_content_elementor'), 10, 3); |
| 19 |
|
| 20 |
// Elementor 3 |
| 21 |
if ( version_compare( ELEMENTOR_VERSION, '3.0.0', '>=' ) ) { |
| 22 |
add_filter( 'elementor/elements/categories_registered', array( __CLASS__,'add_elementor_widget_categories' ), 1, 1 ); |
| 23 |
add_filter( 'elementor/editor/localize_settings', array( __CLASS__,'alter_widget_config' ), 5, 1 ); |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Allow to filter the archive item template content if being edited by elementor. |
| 30 |
* |
| 31 |
* @param $content |
| 32 |
* @param $original_content |
| 33 |
* @param $page_id |
| 34 |
* |
| 35 |
* @return mixed |
| 36 |
*/ |
| 37 |
public function users_list_item_content_elementor($content, $original_content, $page_id){ |
| 38 |
if ( ! $original_content && $page_id && self::is_elementor( $page_id ) ) { |
| 39 |
$original_content = $content = \Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $page_id ); |
| 40 |
} else { |
| 41 |
$original_content = $content; |
| 42 |
} |
| 43 |
|
| 44 |
return $original_content; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Check if a page is being edited by elementor. |
| 49 |
* |
| 50 |
* @return bool |
| 51 |
*/ |
| 52 |
public static function is_elementor( $post_id ) { |
| 53 |
$document = \Elementor\Plugin::$instance->documents->get( $post_id ); |
| 54 |
return $document->is_built_with_elementor(); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Add our own Category. |
| 59 |
* |
| 60 |
* @param $elements_manager |
| 61 |
*/ |
| 62 |
public static function add_elementor_widget_categories( $elements_manager ) { |
| 63 |
|
| 64 |
$elements_manager->add_category( |
| 65 |
'userswp', |
| 66 |
[ |
| 67 |
'title' => esc_html__( 'UsersWP', 'userswp' ), |
| 68 |
'icon' => 'fa fa-plug', |
| 69 |
] |
| 70 |
); |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Force our widget to show for search and to be in our own category. |
| 76 |
* |
| 77 |
* @param $config |
| 78 |
* |
| 79 |
* @return mixed |
| 80 |
*/ |
| 81 |
public static function alter_widget_config( $config ){ |
| 82 |
|
| 83 |
if ( ! empty( $config['initial_document']['widgets'] ) ) { |
| 84 |
foreach( $config['initial_document']['widgets'] as $key => $widget){ |
| 85 |
if(substr( $key, 0, 13 ) === "wp-widget-uwp_"){ |
| 86 |
$config['initial_document']['widgets'][$key]['categories'][] = 'userswp'; |
| 87 |
$config['initial_document']['widgets'][$key]['hide_on_search'] = false; |
| 88 |
$config['initial_document']['widgets'][$key]['icon'] = 'eicon-user-circle-o'; //@todo if no icons use on page then font-awesome is not loaded, wif we can fifure out how to force load we can use icons. <i class="fas fa-globe-americas"></i><i class="fa-solid fa-earth-americas"></i> |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
return $config; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
new UsersWP_Compatibility(); |