data = array();
$this->data['support'] = $data['support'];
$this->data['docs'] = $data['docs'];
$this->data['review'] = $data['review'];
$this->data['css_url'] = $data['css'];
$this->data['images_url'] = $data['image'];
$this->data['slug'] = $data['slug'];
$this->data['menu_slug'] = $data['menu_slug'];
$this->data['version'] = isset( $data['version'] ) ? $data['version'] : '1.0.0';
$this->data['pro_url'] = isset( $data['pro_url'] ) ? $data['pro_url'] : '';
$this->plugin_base_name = "{$this->data['slug']}/{$this->data['slug']}.php";
add_action( 'villatheme_support_' . $this->data['slug'], array( $this, 'villatheme_support' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
add_action( 'admin_notices', array( $this, 'review_notice' ) );
add_action( 'admin_init', array( $this, 'hide_review_notice' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ), 9999 );
add_filter( 'plugin_action_links_' . $this->plugin_base_name, array( $this, 'link_to_pro' ) );
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
/*Admin notices*/
if ( ! get_transient( 'villatheme_call' ) || get_transient( 'villatheme_call' ) == $this->data['slug'] ) {
set_transient( 'villatheme_call', $this->data['slug'], 86400 );
/*Hide notices*/
add_action( 'admin_init', array( $this, 'hide_notices' ) );
add_action( 'admin_notices', array( $this, 'form_ads' ) );
/*Admin dashboard*/
add_action( 'wp_dashboard_setup', array( $this, 'dashboard' ) );
}
}
/**Add link to Documentation, Support and Reviews
*
* @param $links
* @param $file
*
* @return array
*/
public function plugin_row_meta( $links, $file ) {
if ( $this->plugin_base_name === $file ) {
$row_meta = array(
'support' => '' . esc_html__( 'Support', $this->data['slug'] ) . '',
'review' => '' . esc_html__( 'Reviews', $this->data['slug'] ) . '',
);
if ( ! empty( $this->data['docs'] ) ) {
$row_meta['docs'] = '' . esc_html__( 'Docs', $this->data['slug'] ) . '';
}
return array_merge( $links, $row_meta );
}
return (array) $links;
}
/**
* @param $links
*
* @return mixed
*/
public function link_to_pro( $links ) {
if ( ! empty( $this->data['pro_url'] ) ) {
$link = '' . esc_html__( 'Upgrade', $this->data['slug'] ) . '';
array_unshift( $links, $link );
}
return $links;
}
/**wp_remote_get
*
* @param $url
*
* @return array
*/
public function wp_remote_get( $url ) {
$return = array(
'status' => '',
'data' => '',
);
$request = wp_remote_get(
$url,
array(
'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
'timeout' => 1000,
)
);
if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) {
$return['status'] = 'success';
$return['data'] = $request['body'];
} else {
$return['status'] = 'error';
$return['data'] = $request->get_error_message();
}
return $return;
}
/**
* Add Extension page
*/
function admin_menu() {
add_submenu_page(
$this->data['menu_slug'], esc_html__( 'Extensions', $this->data['slug'] ), esc_html__( 'Extensions', $this->data['slug'] ), 'manage_options', $this->data['slug'] . '-extensions', array(
$this,
'page_callback'
)
);
if ( $this->data['menu_slug'] && $this->data['pro_url'] ) {
global $submenu;
$submenu[ $this->data['menu_slug'] ][] = array(
esc_html__( 'Try Premium Version', $this->data['slug'] ),
'manage_options',
$this->data['pro_url']
);
}
}
/**
* Extensions page
* @return bool
*/
public function page_callback() { ?>
data['slug'] ) ?>
data['slug'] ) ?>
wp_remote_get( 'https://villatheme.com/wp-json/info/v1' );
if ( $request_data['status'] === 'success' ) {
$ads = $request_data['data'];
}
set_transient( 'villatheme_ads', $ads, 86400 );
} else {
$ads = $feeds;
}
if ( $ads ) {
$ads = json_decode( $ads );
$ads = array_filter( $ads );
} else {
return false;
}
if ( is_array( $ads ) && count( $ads ) ) {
foreach ( $ads as $ad ) {
?>
image ) { ?>
title ) { ?>
data['slug'] . '_dismiss_notices' ) ) {
update_option( $this->data['slug'] . '_dismiss_notices', 1 );
}
if ( wp_verify_nonce( $_villatheme_nonce, $this->data['slug'] . '_hide_notices' ) ) {
set_transient( $this->data['slug'] . $this->data['version'] . '_hide_notices', 1, 2592000 );
}
if ( wp_verify_nonce( $_villatheme_nonce, $this->data['slug'] . '_wp_reviewed' ) ) {
set_transient( $this->data['slug'] . $this->data['version'] . '_hide_notices', 1, 2592000 );
update_option( $this->data['slug'] . '_wp_reviewed', 1 );
ob_start();
ob_end_clean();
wp_redirect( $this->data['review'] );
die;
}
}
/**
* Show review wordpress
*/
public function review_notice() {
if ( get_option( $this->data['slug'] . '_dismiss_notices', 0 ) ) {
return;
}
if ( get_transient( $this->data['slug'] . $this->data['version'] . '_hide_notices' ) ) {
return;
}
$name = str_replace( '-', ' ', $this->data['slug'] );
$name = ucwords( $name );
$check_review = get_option( $this->data['slug'] . '_wp_reviewed', 0 );
$check_start = get_option( $this->data['slug'] . '_start_use', 0 );
if ( ! $check_start ) {
update_option( $this->data['slug'] . '_start_use', 1 );
set_transient( $this->data['slug'] . $this->data['version'] . '_hide_notices', 1, 259200 );
return;
}
if ( $check_review && ! $this->data['pro_url'] ) {
return;
}
?>
data['slug'] ), array(
$this,
'widget'
) );
}
public function widget() {
$default = array(
'heading' => '',
'description' => '',
'link' => ''
);
$data = get_transient( 'villatheme_notices' );
$called = get_transient( 'villatheme_called' );
if ( ! $data && ! $called ) {
$request_data = $this->wp_remote_get( 'https://villatheme.com/notices.php' );
if ( $request_data['status'] === 'success' ) {
@$data = json_decode( $request_data['data'], true );
}
set_transient( 'villatheme_notices', $data, 86400 );
} else {
set_transient( 'villatheme_called', 1, 86400 );
}
if ( ! is_array( $data ) ) {
return;
}
$data = wp_parse_args( $data, $default );
if ( ! $data['heading'] && ! $data['description'] ) {
return;
} ?>
'',
'description' => '',
'link' => ''
);
$data = get_transient( 'villatheme_notices' );
$called = get_transient( 'villatheme_called' );
if ( ! $data && ! $called ) {
$request_data = $this->wp_remote_get( 'https://villatheme.com/notices.php' );
if ( $request_data['status'] === 'success' ) {
@$data = json_decode( $request_data['data'], true );
}
set_transient( 'villatheme_notices', $data, 86400 );
} else {
set_transient( 'villatheme_called', 1, 86400 );
}
if ( ! is_array( $data ) ) {
return;
}
$data = wp_parse_args( $data, $default );
if ( ! $data['heading'] && ! $data['description'] ) {
return;
}
ob_start(); ?>
data['css_url'] . 'villatheme-support.css' );
}
/**
*
*/
public function villatheme_support() { ?>
wp_remote_get( 'https://villatheme.com/wp-json/info/v1' );
if ( $request_data['status'] === 'success' ) {
@$ads = $request_data['data'];
}
set_transient( 'villatheme_ads', $ads, 86400 );
} else {
$ads = $feeds;
}
if ( $ads ) {
$ads = json_decode( $ads );
$ads = array_filter( $ads );
} else {
return false;
}
if ( is_array( $ads ) && count( $ads ) ) {
$theme_select = null;
foreach ( $ads as $ad ) {
if ( $slug ) {
if ( $ad->slug == $slug ) {
continue;
}
}
$item = new stdClass();
$item->title = $ad->title;
$item->link = $ad->link;
$item->thumb = $ad->thumb;
$item->image = $ad->image;
$item->desc = $ad->description;
$results[] = $item;
}
} else {
return false;
}
if ( is_array( $results ) && count( $results ) ) {
return $results;
} else {
return false;
}
}
}
}