rest-api-to-miniprogram.php 3.6 KB
Newer Older
ijianbo's avatar
ijianbo 已提交
1 2 3 4
<?php
/*
Plugin Name: REST API TO MiniProgram
Plugin URI: http://www.watch-life.net
5
Description: 为微信小程序、app提供定制WordPress REST API 输出.支持微信支付、微信小程序模板消息.
J
jianbo 已提交
6
Version: 1.5
ijianbo's avatar
ijianbo 已提交
7 8 9 10 11 12 13 14 15
Author: jianbo
Author URI: http://www.minapper.com
License: GPL v3
WordPress requires at least: 4.7.0
*/


define('REST_API_TO_MINIPROGRAM_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('REST_API_TO_MINIPROGRAM_PLUGIN_FILE',__FILE__);
16
const REST_API_TO_MINIPROGRAM_PLUGIN_NAME='rest-api-to-miniprogram';
ijianbo's avatar
ijianbo 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

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');
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');

if ( ! class_exists( 'RestAPIMiniProgram' ) ) {

    class RestAPIMiniProgram {
        public $wxapi = null;
        public function __construct() {
            //定制化内容输出,对pc端和api都生效
            add_filter( 'the_content', 'custocm_content_filter' );
            //对文章的自定义输出
            add_filter( 'rest_prepare_post', 'custom_post_fields', 10, 3 );            
            //对评论的自定义输出
            add_filter( 'rest_prepare_comment', 'custom_comment_fields', 10, 3 );
            add_filter( 'rest_prepare_category', 'custom_fields_rest_prepare_category', 10, 3 ); //获取分类的封面图片


ijianbo's avatar
ijianbo 已提交
41 42 43 44 45

            //更新浏览次数(pc)
            add_action('wp_head', 'addPostPageviews');

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

ijianbo's avatar
ijianbo 已提交
48 49 50 51 52 53
            
            // 管理配置 
            if ( is_admin() ) {             
                
                //new WP_Category_Config();
                add_action('admin_menu', 'weixinapp_create_menu');
54
                add_filter( 'plugin_action_links', 'ram_plugin_action_links', 10, 2 );
ijianbo's avatar
ijianbo 已提交
55 56 57 58 59 60 61 62 63 64 65
                 
            }

            new RAM_API();//api
            $this->wxapi = new RAW_Weixin_API();


        }

        

66
    }
ijianbo's avatar
ijianbo 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80


    // 实例化并加入全局变量
    $GLOBALS['RestAPIMiniProgram'] = new RestAPIMiniProgram();
    
    function RAW() {
        
        if( ! isset( $GLOBALS['RestAPIMiniProgram'] ) ) {
            $GLOBALS['RestAPIMiniProgram'] = new RestAPIMiniProgram();
        }
        
        return $GLOBALS['RestAPIMiniProgram'];
    }

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    function ram_plugin_action_links( $links, $file ) {
        if ( plugin_basename( __FILE__ ) !== $file ) {
            return $links;
        }

        $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 );


        $settings_link = '<a href="https://www.watch-life.net/" target="_blank"> <span style="color:green; font-weight:bold;">' . esc_html__( '技术支持', 'REST API TO MiniProgram' ) . '</span></a>';

        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 已提交
102
}