rest-api-to-miniprogram.php 5.6 KB
Newer Older
J
update  
jianbo 已提交
1
<?php
ijianbo's avatar
ijianbo 已提交
2
/*
J
jianbo 已提交
3
Plugin Name: REST API TO MiniProgram 微慕小程序
4
Plugin URI: https://www.minapper.com
J
jianbo 已提交
5
Description: 为微信小程序、app提供定制化WordPress REST API json 输出.
J
jianbo 已提交
6
Version: 4.0.4
ijianbo's avatar
ijianbo 已提交
7
Author: jianbo
8
Author URI: https://www.minapper.com
ijianbo's avatar
ijianbo 已提交
9
License: GPL v3
J
update  
jianbo 已提交
10
WordPress requires at least: 4.7.1
ijianbo's avatar
ijianbo 已提交
11 12 13 14
*/


define('REST_API_TO_MINIPROGRAM_PLUGIN_DIR', plugin_dir_path(__FILE__));
15
const REST_API_TO_MINIPROGRAM_PLUGIN_NAME='rest-api-to-miniprogram';
J
jianbo 已提交
16 17
define('REST_API_TO_MINIPROGRAM_PLUGIN_URL',plugins_url(REST_API_TO_MINIPROGRAM_PLUGIN_NAME.'/', dirname(__FILE__)));

ijianbo's avatar
ijianbo 已提交
18 19 20 21 22

include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/ram-util.php' );
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/ram-api.php' );
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/ram-weixin-api.php');
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/settings/wp-wechat-config.php');
J
jianbo 已提交
23
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/settings/wp-post-config.php');
J
jianbo 已提交
24
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/settings/wp-tinymce-add-button.php');
ijianbo's avatar
ijianbo 已提交
25 26 27 28
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/filter/ram-custom-comment-fields.php');
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/filter/ram-custom-content.php');
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/filter/ram-custom-post-fields.php');
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/filter/ram-custom-category.php');
J
jianbo 已提交
29
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/filter/ram-custom-users-columns.php');
J
jianbo 已提交
30 31
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/filter/ram-custom-category-rows.php');
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/filter/ram-custom-posts-rows.php');
32 33
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/admin/exopite-simple-options/exopite-simple-options-framework-class.php');
include(REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/settings/wp-wechat-admin.php');
ijianbo's avatar
ijianbo 已提交
34 35 36 37 38 39 40 41
if ( ! class_exists( 'RestAPIMiniProgram' ) ) {

    class RestAPIMiniProgram {
        public $wxapi = null;
        public function __construct() {
            //定制化内容输出,对pc端和api都生效
            add_filter( 'the_content', 'custocm_content_filter' );
            //对文章的自定义输出
J
jianbo 已提交
42 43 44
            add_filter( 'rest_prepare_post', 'custom_post_fields', 10, 3 ); 
            //对页面的自定义输出
			add_filter( 'rest_prepare_page', 'custom_post_fields', 10, 3 );           
ijianbo's avatar
ijianbo 已提交
45 46 47 48
            //对评论的自定义输出
            add_filter( 'rest_prepare_comment', 'custom_comment_fields', 10, 3 );
            add_filter( 'rest_prepare_category', 'custom_fields_rest_prepare_category', 10, 3 ); //获取分类的封面图片

J
jianbo 已提交
49 50
            add_filter( 'manage_users_columns', 'users_columns' );
			add_action( 'manage_users_custom_column', 'output_users_columns', 10, 3 );
J
jianbo 已提交
51 52
			//给TinyMCE编辑器增加A标签按钮
			add_action('after_wp_tiny_mce', 'add_tinyMCE_minapper_button');
ijianbo's avatar
ijianbo 已提交
53

J
jianbo 已提交
54 55 56 57 58
            
			//文章页显示自定义列
			add_filter( 'manage_posts_columns' , 'ram_posts_columns' );
			add_action( 'manage_posts_custom_column' , 'output_ram_posts_custom_columns', 10, 3 );

J
jianbo 已提交
59 60 61 62
            //页面显示自定义列
			add_filter( 'manage_pages_columns' , 'ram_pages_columns' );
			add_action( 'manage_pages_custom_column' , 'output_ram_pages_custom_columns', 10, 3 );

ijianbo's avatar
ijianbo 已提交
63

J
jianbo 已提交
64 65 66
            //分类目录页自定义列
			add_filter('manage_edit-category_columns' , 'ram_custom_taxonomy_columns');
			add_filter( 'manage_category_custom_column', 'ram_custom_taxonomy_columns_content', 10, 3 );
ijianbo's avatar
ijianbo 已提交
67 68 69 70
            //更新浏览次数(pc)
            add_action('wp_head', 'addPostPageviews');

            //获取浏览次数(pc)
71
            //add_filter('raw_post_views', 'post_views');
ijianbo's avatar
ijianbo 已提交
72

ijianbo's avatar
ijianbo 已提交
73 74 75 76 77
            
            // 管理配置 
            if ( is_admin() ) {             
                
                //new WP_Category_Config();
J
jianbo 已提交
78
               add_action('admin_menu', 'weixinapp_create_menu');
79
               add_action('init','minapper_admin_menu');
J
jianbo 已提交
80
               add_filter( 'plugin_action_links', 'ram_plugin_action_links', 10, 2 );
J
jianbo 已提交
81
               wp_post_config();
ijianbo's avatar
ijianbo 已提交
82 83 84 85
                 
            }

            new RAM_API();//api
J
jianbo 已提交
86
            $this->wxapi = new RAM_Weixin_API();
ijianbo's avatar
ijianbo 已提交
87 88 89 90 91 92


        }

        

93
    }
ijianbo's avatar
ijianbo 已提交
94 95 96 97 98


    // 实例化并加入全局变量
    $GLOBALS['RestAPIMiniProgram'] = new RestAPIMiniProgram();
    
J
jianbo 已提交
99
    function RAM() {
ijianbo's avatar
ijianbo 已提交
100 101 102 103 104 105 106 107
        
        if( ! isset( $GLOBALS['RestAPIMiniProgram'] ) ) {
            $GLOBALS['RestAPIMiniProgram'] = new RestAPIMiniProgram();
        }
        
        return $GLOBALS['RestAPIMiniProgram'];
    }

108 109 110 111 112
    function ram_plugin_action_links( $links, $file ) {
        if ( plugin_basename( __FILE__ ) !== $file ) {
            return $links;
        }

J
jianbo 已提交
113 114 115 116
        $settings_link = '<a href="https://www.minapper.com/" target="_blank"> <span style="color:#d54e21; font-weight:bold;">' . esc_html__( '升级增强版', 'REST API TO MiniProgram' ) . '</span></a>';

        array_unshift( $links, $settings_link );

117 118 119 120 121
        $settings_link = '<a href="https://www.minapper.com/" target="_blank"> <span style="color:#d54e21; font-weight:bold;">' . esc_html__( '升级专业版', 'REST API TO MiniProgram' ) . '</span></a>';

        array_unshift( $links, $settings_link );


J
jianbo 已提交
122
        $settings_link = '<a href="https://www.minapper.net/" target="_blank"> <span style="color:green; font-weight:bold;">' . esc_html__( '技术支持', 'REST API TO MiniProgram' ) . '</span></a>';
123 124 125 126 127 128 129 130 131 132

        array_unshift( $links, $settings_link );

        $settings_link = '<a href="admin.php?page=weixinapp_slug">' . esc_html__( '设置', 'REST API TO MiniProgram' ) . '</a>';

        array_unshift( $links, $settings_link );

        return $links;
    }

ijianbo's avatar
ijianbo 已提交
133
}