-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-one-viewer.php
107 lines (77 loc) · 2.49 KB
/
wp-one-viewer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/*
Plugin Name: One Viewer
Plugin URI: https://github.com/TR4HIM
Description: Allows to show worpdress posts by categories using VueJs and Wordpress API
Author: Soufiane Trahim
Version: 1.0.0
Author URI: https://github.com/TR4HIM
Requires at least: 4.9
*/
if(!defined('ABSPATH')) {die('You are not allowed to call this page directly.');}
/* Plugin Constans */
define( 'ONEVIEW_VERSION', '1.0.0' );
define( 'ONEVIEW_REQUIRED_WP_VERSION', '4.9' );
define( 'ONEVIEW_PLUGIN', dirname( __FILE__ ) );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-viewer-per-category-activator.php
*/
function activate_one_viewer() {
/**
* Add option field to save selected categories
*/
add_option('oneviewer_categories',1);
/**
* Check if /viewer page already exist
*
*/
$checkViewerPage = get_page_by_path('viewer');
/**
* Create page viewer if it's not exist
*/
if(empty($checkViewerPage)){
$post_data = array(
'post_title' => wp_strip_all_tags( "Viewer" ),
'post_content' => '',
'post_status' => 'publish',
'post_type' => 'page',
'post_author' => get_current_user_id(),
);
wp_insert_post( $post_data);
}
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-viewer-per-category-deactivator.php
*/
function deactivate_one_viewer() {
}
register_activation_hook( __FILE__, 'activate_one_viewer' );
register_deactivation_hook( __FILE__, 'deactivate_one_viewer' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-one-viewer-endpoints.php';
require plugin_dir_path( __FILE__ ) . 'includes/class-one-viewer.php';
// Overwrite the default tempalte for /viewer page
add_filter( 'template_include', 'oneviewer_page_template', 99 );
function oneviewer_page_template( $template ) {
// Check if it's viewer page
if ( is_page('viewer') ) {
$newtemplate = dirname( __FILE__ ) . '/templates/page-one-viewer.php';
return $newtemplate ;
}
return $template;
}
/*
One Viewer Run
*/
function wp_one_viewer_run () {
$urlsInit = new OneViewerEndPoint();
$urlsInit->Register_Endpoint();
$plugin = new OneViewerCore();
$plugin->init();
}
wp_one_viewer_run ();