=' ) || !version_compare( $wp_version, '3.0', '>=' ) ) { if( IS_ADMIN && ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) ) { require_once ABSPATH.'/wp-admin/includes/plugin.php'; deactivate_plugins( __FILE__ ); wp_die( __('Attachments requires PHP 5.2 or higher, as does WordPress 3.2+. Attachments has been automatically deactivated.') ); } else { return; } } // we moved all attachments_get_attachments() functions to an external file in version 3.0 include_once 'get-attachments.php'; // ========= // = HOOKS = // ========= if( IS_ADMIN ) { // pre-flight check add_action( 'init', 'attachments_pre_init' ); // get our assets in line add_action( 'admin_enqueue_scripts', 'attachments_enqueues' ); add_action( 'admin_head', 'attachments_init_js' ); // get our menu in line add_action( 'admin_menu', 'attachments_menu' ); // need our textdomain add_action( 'plugins_loaded', 'attachments_localization' ); // make sure we've got our settings in place add_action( 'admin_init', 'attachments_register_settings' ); // make sure we handle the save add_action( 'save_post', 'attachments_save' ); // invoke our meta box add_action( 'add_meta_boxes', 'attachments_meta_box' ); } function attachments_localization() { load_plugin_textdomain( 'attachments', false, ATTACHMENTS_DIR . '/languages/' ); } function attachments_enqueues( $hook ) { wp_enqueue_style( 'attachments', trailingslashit( ATTACHMENTS_URL ) . 'css/attachments.css' ); if( 'edit.php' != $hook && 'post.php' != $hook && 'post-new.php' != $hook ) return; wp_enqueue_script( 'handlebars', trailingslashit( ATTACHMENTS_URL ) . 'js/handlebars.js', null, '1.0.beta.6', false ); wp_enqueue_script( 'attachments', trailingslashit( ATTACHMENTS_URL ) . 'js/attachments.js', array( 'handlebars', 'jquery', 'thickbox' ), ATTACHMENTS_VERSION, true ); wp_enqueue_style( 'thickbox' ); } // ============= // = FUNCTIONS = // ============= function attachments_pre_init() { // as of version 1.6 we'll be storing a proper settings array if( !get_option( ATTACHMENTS_PREFIX . 'settings' ) ) { $settings = array(); // we've got a version < 1.6 and therefore no real settings $settings['version'] = ATTACHMENTS_VERSION; $post_parent = get_option( 'attachments_store_native' ); if( $post_parent === false ) { // it wasn't set $settings['post_parent'] = false; } else { $settings['post_parent'] = true; } // grab our custom post types $args = array( 'public' => true, 'show_ui' => true, '_builtin' => false ); $output = 'objects'; $operator = 'and'; $post_types = get_post_types( $args, $output, $operator ); // we also want to optionally enable Pages and Posts $post_types['post']->labels->name = 'Posts'; $post_types['post']->name = 'post'; $post_types['page']->labels->name = 'Pages'; $post_types['page']->name = 'page'; if( count( $post_types ) ) { foreach( $post_types as $post_type ) { $post_parent = get_option( 'attachments_cpt_' . $post_type->name ); if( $post_parent === false ) { // it wasn't set $settings['post_types'][$post_type->name] = false; } else { $settings['post_types'][$post_type->name] = true; } } } // save our settings update_option( ATTACHMENTS_PREFIX . 'settings', $settings ); } } function attachments_register_settings() { // flag our settings register_setting( ATTACHMENTS_PREFIX . 'settings', ATTACHMENTS_PREFIX . 'settings', 'attachments_validate_settings' ); add_settings_section( ATTACHMENTS_PREFIX . 'options', 'Post Type Settings', 'attachments_edit_options', 'attachments_options' ); // post types add_settings_field( ATTACHMENTS_PREFIX . 'post_types', 'Post Types', 'attachments_edit_post_types', 'attachments_options', ATTACHMENTS_PREFIX . 'options' ); // post_parent add_settings_field( ATTACHMENTS_PREFIX . 'post_parent', 'Set Post Parent', 'attachments_edit_post_parent', 'attachments_options', ATTACHMENTS_PREFIX . 'options' ); } function attachments_edit_options() { } function attachments_validate_settings($input) { $input['version'] = ATTACHMENTS_VERSION; return $input; } function attachments_edit_post_parent() { $settings = get_option( ATTACHMENTS_PREFIX . 'settings' ); ?>