예제 #1
0
 /**
  * Initialize plugin enviroment
  */
 public static function init()
 {
     global $wp_version, $post;
     // load translations from locale
     load_plugin_textdomain('wp-cred', false, CRED_LOCALE_PATH);
     // load help settings (once)
     self::$help = CRED_Loader::getHelpSettings();
     // set up models and db settings
     self::prepareDB();
     self::$settingsPage = admin_url('admin.php') . '?page=CRED_Settings';
     if (is_admin()) {
         // setup js, css assets
         add_action('admin_enqueue_scripts', array('CRED_CRED', 'cred_admin_head'));
         // add plugin menus
         add_action('admin_menu', array('CRED_CRED', 'addMenuItems'));
         // add media buttons for cred forms at editor
         if (version_compare($wp_version, '3.1.4', '>')) {
             add_action('media_buttons', array('CRED_CRED', 'addFormsButton'), 20, 2);
         } else {
             add_action('media_buttons_context', array('CRED_CRED', 'addFormsButton'), 20, 2);
         }
         // integrate with Views
         add_filter('wpv_meta_html_add_form_button', array('CRED_CRED', 'addCREDButton'), 20, 2);
         // add custom meta boxes for cred forms
         add_action('add_meta_boxes_' . CRED_FORMS_CUSTOM_POST_NAME, array('CRED_CRED', 'addMetaBoxes'), 20, 1);
         // save custom fields of cred forms
         add_action('save_post', array('CRED_CRED', 'saveFormCustomFields'), 10, 2);
         //add_filter( 'default_content', array('CRED_CRED','formDefaultValues'), 10, 2 );
         add_filter('wp_insert_post_data', array('CRED_CRED', 'forcePrivateforForms'));
         // add custom js on certain pages
         if (version_compare($wp_version, '3.3', '>=')) {
             //add_action('admin_head-edit.php', array($this, 'admin_add_help'));
             add_action('admin_head-post.php', array('CRED_CRED', 'jsForCredCustomPost'));
             add_action('admin_head-post-new.php', array('CRED_CRED', 'jsForCredCustomPost'));
         }
         if (version_compare($wp_version, '3.2', '>=')) {
             if (isset($post) && $post->post_type == CRED_FORMS_CUSTOM_POST_NAME) {
                 remove_action('pre_post_update', 'wp_save_post_revision');
             }
         }
     } else {
         // add form short code hooks and filters, to display forms on front end
         self::addShortcodesandFilters();
     }
     // stub wpml-string shortcode
     if (!self::check_wpml_string()) {
         // WPML string translation is not active
         // Add our own do nothing shortcode
         add_shortcode('wpml-string', array('CRED_CRED', 'stub_wpml_string_shortcode'));
     } else {
         $wpml_was_active = get_option(self::$cred_wpml_option);
         // if changes before wpml activated, re-process all forms
         if ($wpml_was_active && $wpml_was_active == 'no') {
             //cred_log('process all forms');
             CRED_Loader::load('CLASS/Form_Processor');
             $cfp = new CRED_Form_Processor(null, null);
             $cfp->processAllFormsForStrings();
             update_option(self::$cred_wpml_option, 'yes');
         }
     }
     // setup custom capabilities
     self::setupCustomCaps();
     // setup extra admin hooks for other plugins
     self::setupExtraHooks();
     if (!is_admin()) {
         // init form processing to check for submits
         CRED_Loader::load('CLASS/Form_Builder');
         CRED_Form_Builder::init();
     }
     // handle custom routes, for (quasi) admin section
     CRED_Loader::load('CLASS/Router');
     CRED_Router::init();
     // handle Ajax calls
     CRED_Loader::load('CLASS/Ajax_Router');
     CRED_Ajax_Router::init();
 }
예제 #2
0
 public static function route($path = '', $params = null, $raw = true)
 {
     return CRED_Router::getRoute('cred', $path, $params, $raw);
 }